如何编写node.jsasynchronous内部for循环?

我开始构buildnodejs应用程序来从具有分页的网站上刮取数据。 我写循环获取所有页面,并推动所有的URL存储在一个数组中。 在那个for循环里,我写async.eachSeries来一个接一个地运行所有的url,在运行完成之后,我想打印出成功的消息。 但我不知道如何把它们放在一起才能正常工作。 这是我的代码

for(var pageNo = 1; pageNo <=200; pageNo++){ siterequest('https://www...../en/jobs/?by=&in=&page='+pageNo, function(err, res, body){ if(!err && res.statusCode ==200){ var $ = cheerio.load(body); var links = []; $('.headline3.job-name-title > strong > a').each(function(i, elem){ links.push('https://www......com.kh/'+$(elem).attr('href')); }); async.eachSeries(links, function(uri, next){ console.log('i will go this '+uri); next(); }, function(callback){ console.log('I did it'); }); }; }); }; 

上面的代码不适合我。 请帮帮我! 提前致谢

在使用async.js时,您可以尝试使用async.times而不是for loop

 async.times(200, function (paneNo, nextPage) { siterequest('https://www...../en/jobs/?by=&in=&page=' + (pageNo + 1), function (err, res, body) { if (!err && res.statusCode ==200) { var $ = cheerio.load(body); var links = []; $('.headline3.job-name-title > strong > a').each(function (i, elem) { links.push('https://www......com.kh/'+$(elem).attr('href')); }); async.eachSeries(links, function (uri, next) { console.log('i will go this '+ uri); next(); }, function(callback) { nextPage(); }); } else { nextPage(err); } }); }, function(err) { console.log('Done!'); });