我正在使用NODEJS的jsdom进行网络抓取。我尝试了很多方法,如async.queue,系列等等。我完全想找出解决方案,我知道我在最后,但不知道如何获得所有的模型数据。
让我们假设,我想刮掉所有的类别和他们的产品。
类别->产品-->型号
Mobile (Category) url is cat/mb
Iphone (product) url is cat/mb/iphone
Iphone 4 (model) url is cat/mb/iphone/iphone-4
Iphone 5 (model) url is cat/mb/iphone/iphone-5
Laptop (Category) url is cat/lp
Sony (product) url is cat/lp/sony
F Series (model) url is cat/lp/sony/fseries
E Series (model) url is cat/lp/sony/eseries概念是,获取所有的类别,他们的产品和他们的模型信息数据。
预期输出:
I Phone 4
I Phone 5
F series
E series但是在我的代码中,由于瀑布中的每个循环,没有得到所有的模型信息(),所以我丢失了太多的模型数据。
I得到的输出如下:
F series主代码位于下面的中
async.each(pagination_values, function(paginateNum, callback) {
var endpointUrl = catEndpointUrl + '&order=panel_id&by=desc&page='+paginateNum;// 'http://www.panelook.com/appmodlist.php?order=panel_id&by=desc&applications[]=CNS&page='+paginateNum;
var baseurl = 'http://www.panelook.com/';
logger.info('Step 4: Product Pagination '+ paginateNum + ' - ' + endpointUrl);
async.waterfall([
function(callback) {
helperObj.fetchPageContent(endpointUrl, function(html) {
logger.info('Step 5: Product URL '+ endpointUrl);
callback(null, html);
});
},
function(html, callback) {
env({html:html,
done:function (err, window) {
if(err)
console.log(err.message);
var productList =[]
var $ = require('jquery')(window);
//............the below each function is not async i guess, Therefore, i am not getting all the models data..what to do ?...........
//
$('form#modelcompare table#listable tr').each(function() {
if($(this).find('td:nth-child(2)').text() != ''){
logger.info('All the data ' + $(this).find('td:nth-child(2) a').attr('href'));
}
});
callback();
}
});
}
], function(err, results) {
if(err)
console.log(err.message);
});
}, function(err) {
if(err)
console.log(err.message);
});发布于 2014-12-31 14:07:36
您可以在q (链接)中使用诺言。
按部就班地写东西就像
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(promisedStep4)
.then(function (value4) {
// Do something with value4
})
.catch(function (error) {
// Handle any error from all above steps
})
.done();https://stackoverflow.com/questions/27721446
复制相似问题