从Nightmare.js返回HTML正文

我目前正在做一些与cheerionightmare刮。 我之所以用这两种而不仅仅是cheerio是因为我必须操纵这个网站才能find我想要的部分,而且我发现这些剧本的噩梦非常好。

所以,现在我正在使用nightmare ,直到我需要的信息显示部分。 之后,在evaluate()我试图以某种方式返回当前的html ,然后传递给cheerio做刮。 问题是我不知道如何从document对象中检索html。 文件中是否有属性返回完整的主体?

这是我想要做的:

 var Nightmare = require('nightmare'); var nightmare = Nightmare({show:true}) var express = require('express'); var fs = require('fs'); var request = require('request'); var cheerio = require('cheerio'); var app = express(); var urlWeb = "url"; var selectCity = "#ddl_city" nightmare .goto(urlWeb) .wait(selectCity) .select('#ddl_city', '19') .wait(6000) .select('#ddl_theater', '12') .wait(1000) .click('#btn_enter') .wait('#aspnetForm') .evaluate(function(){ //here is where I want to return the html body return document.html; }) .then(function(body){ //loading html body to cheerio var $ = cheerio.load(body); console.log(body); }) 

有了这个工作:

 document.body.innerHTML