使用nodejs的request模块和async模块做网页爬虫,爬完指定批量数据后爬虫并没有停止,如果加一个计数器,觉得很麻烦。请问这个要怎么处理比较好?先谢谢了!
http.get(url,function(res){
res.setEncoding('utf-8');
var html = '';
res.on('data',function(chunk){
html += chunk;
});
res.on('end',function(){
// console.log(html);return;
var $ = cheerio.load(html);
$('.type-item-list-left').find('a').each(function(){
var link = $(this).attr('href').trim();
urls.push(link);
});
async.each(urls,function(item,callback){
detail(item,keyword);
callback();
},function(err){
if(err){
console.log('err:' + err);
}
})
});
}).on('error',function(err){
console.log(err);
});
是不是写了什么死循环?