2016-09-25 39 views
3

我目前正在使用cheerionightmare進行一些刮擦。我之所以用這兩個而不僅僅是cheerio是因爲我必須操縱網站才能找到我想要抓取的部分,並且我發現這些劇本非常擅長惡夢。從Nightmare.js返回HTML正文

所以,現在我正在使用nightmare來獲取我需要的信息顯示的部分。之後,在evaluate()我試圖以某種方式返回當前html然後傳遞給cheerio做刮擦。問題是我不知道如何從document對象中檢索html。 document是否有財產返回全身?

這裏是我想要做的事:

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); 
}) 
+0

你需要的所有'html'或者是'document.body'足夠了嗎? –

+0

到目前爲止,我只需要body @ R.A.Lucas –

+0

從'evaluate'方法返回'document.body'是否工作? –

回答

5

有了這個工作:

document.body.innerHTML