我目前正在使用cheerio和nightmare进行一些抓取工作。我之所以同时使用这两个工具,而不仅仅是cheerio,是因为我必须操纵网站才能找到我想要抓取的部分,而且我发现噩梦非常擅长做这些脚本。
所以,现在我正在使用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);
})发布于 2016-09-26 06:18:20
在此基础上:
document.body.innerHTMLhttps://stackoverflow.com/questions/39691531
复制相似问题