我试图抓一个通过jS填充的网页,但是cheerio一直在回复一个""在刮擦特定元素时返回。
我的node.js文件:
var five = require("johnny-five");
var board = new five.Board();
var request = require('request');
var cheerio = require('cheerio');
function scoreRequest(callback){
request('http://selfiesoldier.co/jsmidterm/newindex.html', function (error, response, body) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(body);
var a = $(".answer").html();
console.log(body);
board.on("ready", function() {
var array = new five.Leds([3, 5, 6]);
if (a == "NO") {
array[0].pulse();
array[2].off();
console.log("GREEN")
console.log(a);
} else if (a == "YES") {
array[0].off();
array[2].pulse();
console.log("RED");
console.log(a);
}
});
}
callback();
});
}
function wait10sec(){
setTimeout(function(){
scoreRequest(wait10sec);
console.log("its been 10 sec");
}, 10000);
}
scoreRequest(wait10sec);
jS正在填充h1.answer HTML标记,它根据某些JSON数据确定内容(是或否)。
然而,当我运行脚本时,我得到一个空白的响应而不是" NO"或"是"。