im using x-ray, which is great but lack of tutorial. anyway, I use an array of urls named urls. In the loop ,each url fetched and return result through callback. in the callback function i need to know what was the url which was parsed. How can i know which url is returning if the callback returns only err and results? (is it really an x-ray question or js)
xrayRamiLevy = function(){
var index = 0;
for (index; index < urls.length; index++){
x(urls[index].url, '.product_item',
[{
title : '.prodDescDiv h3',
description : '.prodBrand',
imageUrl : '.image_icons_zone .image img@src',
onclick : '.image_icons_zone .image a @onclick',
}]
)
(function(err, results){
for (var i = 0; i < results.length; i++){
var s = results[i].onclick.substr(0, results[i].onclick.lastIndexOf("'"));
s = s.slice(s.lastIndexOf("'") + 1);
results[i].catalogueNumber = s;
delete results[i].onclick;
if (results[i].description !== undefined && results[i].description.length > 0)
s = results[i].description.replace(/\s+/g, ' ').trim();
results[i].description = s;
if (urls[index].category !== undefined && urls[index].category.length > 0)
results[i].categoriesIds = urls[index].category;
if (urls[index].subcategory !== undefined && urls[index].subcategory.length > 0)
results[i].subcategoriesIds = urls[index].subcategory;
}
fs.writeFile("./results.json", JSON.stringify(results, null, '\t'));
});
} }