I'm trying to write some parser on node. I can't understand something here. I need to stop requesting next pages if previous result was wrong. My current code is something like this:
var request = require('request');
var cheerio = require('cheerio');
var links = ['http://link1','http://link2','http://link3'];
for(l in links) {
var link = links[l];
request(link, function(err, page) {
if(err) throw err;
$ = cheerio.load(page.body);
if($('a').length < 2) {
// here i need to stop requesting next url(s) from links array somehow!
// (if this is the case of link1 then link2 and link3 will not request)
} else {
// do something...
}
$.html();
});
}