itemCount ++;
if (itemCount === items) {
pageCount ++;
if (pageCount === pages) cb(null);
async.eachSeries(webSites, function (site, cb___) {
fs.appendFile(filepath, site, function (err) {
if (err) console.error(err);
});
cb___();
});
cb_();
}
cb__();
我写的爬虫,在爬了一个page的所有item之后,还要深入到每个item里面取数据,取完之后写到文件里去,然后再爬下一个页面。
我使用了多层嵌套async.eachSeries之后发现,我只会在最深层级的回调中获取外层(套了很多层)的回调次数然后判断是不是继续下一步,所以写了很多的计数器。
有没有更好的解决方法呢?