Unable to iterate over an array

ساخت وبلاگ

Vote count: 0

I am building a web scraper in CasperJS. I am trying to iterate over the allLinks array which contains all the links I want to scrape. Following are code snippets that I have tried.

1)

casper.then(function(){ this.each(allLinks,function(self,link){ console.log("Inside the each function"); console.log(link); (function(link){ this.thenOpen(link,function(a){ console.log("Inside function that extracts data"); console.log(link); })(link);
}); });

2)

casper.then(function(){ var i = 0; var length = allLinks.length; var arr = new Array(75); //console.log(length); //console.log(allLinks); casper.repeat(length,function(){
arr[i] = allLinks[i]; //console.log(length); console.log(i); link = allLinks[i]; //console.log("Inside function each "); console.log("1" + link); //console.log(typeof(link)); //var eachLink = getLink(link); i++; if (i == 74) { console.log(arr.length); console.log(arr); }
}); });

3)

 casper.then(function(){ while(j < allLinks.length) { console.log("Inside the each function"); //console.log(allLinks); this.thenOpen(allLinks[j],function(a){ console.log("Inside function that extracts data"); console.log(j); console.log(allLinks[j]); }; j = j + 1; }); });

4)

casper.then(function(){ for(j = 0; j < allLinks.length; j++) { console.log("Inside the each function"); //console.log(allLinks); this.thenOpen(allLinks[j],function(a){ console.log("Inside function that extracts data"); console.log(j); console.log(allLinks[j]); }; });
});

5)

casper.then(function(){ this.each(allLinks,function(self,link){ console.log("Inside the each function"); console.log(link); this.thenOpen(link,function(a){ console.log("Inside function that extracts data"); console.log(link);
}; }); });
asked 50 secs ago

- - , .

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 338 تاريخ : جمعه 30 بهمن 1394 ساعت: 12:36