var async = require("async");
var citysUrl=[];
var urlsArray=[];
async.eachSeries(citysUrl, function (city, nextcity) {//城市循环
channels.forEach(function (channel) {//组合url
var options = GetOptions(channel);
options.forEach(function (option) {
var pageurl = GetUrl(city, channel, option);
urlsArray.push(pageurl);
});
});
console.log("开始抓取" + GetcityName(city) + "的产品信息");
async.eachSeries(urlsArray, function (url, next) {
async.waterfall([function(cb){
Grab(url,cb);//Grab为异步抓取url操作function(url,cb){此处省略一万字//异步完成时调用cb(null,html);}
},
function(data,cb){
console.log('分析html');
cb(null,2)
}],function(err,data){
console.log('一次循环结束');
next();
});
}, function (err,data) {
console.log(GetcityName(city) + "产品抓取完成");
urlsArray = [];
nextcity();
});
}, function () {
console.log('所有城市产品抓取完成');
process.exit();
});