Simultaneous CasperJS Requests

Suppose I have an array of URLs. I do not want to use the thenOpen function. Because he expects every previous URL to be loaded, and this will reduce the loading time.

casper.each(hrefs,function(self,href){ self.thenOpen(href,function(){ }); self.then(function(){ // Selectors }); 

});

What methods would you spend much less than the above method? It would be efficient to create several instance repositories in db and then get ... but this is a lot of headache. And I would also like you to also answer that I will have problems when I simultaneously run several instances of the same js file?

+7
casperjs
source share
2 answers

If you do not need to synchronize behavior between all open URLs, you must run multiple instances of casper for each URL. Here is an example:

 var casperActions = { href1: function (casper) { casper.start(address, function() {...}); // tests and what not for href1 casper.run(function() {...}); }, href2: function (casper) { casper.start(address, function() {...}); // tests and what not for href2 casper.run(function() {...}); }, ... }; ['href1', 'href2', ...].each(function(href) { var casper1 = require('casper').create(); casperActions[href](casper); }); 

Each instance will work independently, but this will allow you to remove multiple URLs at once.

+9
source share

If you want to wait for the completion of each operation to complete the sequence of steps, look at this trial delivery with casper: https://github.com/n1k0/casperjs/blob/1.0/samples/multirun.js

+1
source share

All Articles