I'm trying to scrape a webpage that is populated via jS, but cheerio keeps returning a "" return when it scrapes a particular element.
My node.js file:
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);
The h1.answer HTML tag is being populated by jS which determines the content (YES or NO) depending on some JSON data.
When I run the script however, I get a blank response instead of "NO" or "YES".