I use request modules and cheerio node to create some data from the site. I would like to get a list of items, and as soon as this list is complete, call the asynchronous function:
request('http://myurl', function(req,res,data){
var $ = cheerio.load(data);
var List = [];
$('.myItems').each(function(i, element){
console.log( typeof $(this).text() )
List.push($(this).text());
});
for (var i=0; i < List.length; i++){
}
});
My question is: how to wait for the list to complete, i.e. how can i find out that the .each function is looping on all elements?
Can I do this with async?
thank
source
share