I'm trying to parse a site where data are loaded js script by clicking on the button. I need to write a function that will search for the number of loaded pages. I think to write a recursive function , but how to do it with an asynchronous node js?
var request = require('request');
var cheerio = require('cheerio');
var counter = function (link, i) {
request(link + i, function (error, response, body) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(body);
if ($('.b-products__list .main-bigger3').text().trim() == 'end of parse') {
return i;
}
else{
i++;
counter(link);
}
}
})
};
module.exports = counter;
Aucun commentaire:
Enregistrer un commentaire