multithreading - PhantomJS-Node in a for Loop -


I am trying to implement a screen-scraps application that opens a URL in which a parameter changes as it is for a loop:

  var data = [ '100', '101', '102', '103', '104']; (Var indexA = 0; indexA & lt; data.length; indexA ++) for {Phantom Generation ({'port': freeport}, function (pH) {ph.create page (function (page) {page.open ("http: //...++ data [index B] +" ... " , Status {console.log ("open site:" + data [index B], position); / * OLD * / indexB ++; page evaluation (function () {// page scrape and an object Return}, function {console.log (result.dataRequest); // here is the problem}); / * new and fixed * / indexB ++}   

first console Logs it:

  Open Site: 100 Success Opens Site: 101 Success B Ola Site: 102 Success Opening Site: 103 Success Opened Site: 104 Success   

Which is good.

Data is verified in scrap HTML and from index to array Matches. So in page 101 I scrap '101 and retrieve' and put it in the result. But when I get the result.dataRequest console me to log in:

  100 Do with 101 102 102 102   

My theory: a multi-processing problem. I do not understand When actually the new phantomJS hair procedure is being made, and when it is being removed, should I have some type of Mute X (JS Version of a Mute X) around the result type of callback? This is causing a problem, because I want to insert the result in dB, and when I check my DB, so I get duplicate the same results.

Thank you!

IMO, the problem is that JS is asynchronous, it seems that you have phatcom for loop processing Comparing the process faster.

You can not determine how the asynchronous method will be run (about call orders and goods) I mean most of the time in your example, you can not make sure that the phantom The previous order B ++,

will apparently be in your log, it works fine for 100 101 102, but the fourth loop, if you make an example of the phantom, then you start a new loop Do the steps, "index + +;" Not happy yet you do a step loop with B once one indicator ....

tl, dr: what is it the same in your case: < make pre> to create.phantom 101 100 ++ Bnaaakfantm Pentim to make 102 to 101 101 ++ 102. Make 102 102. Pentm 102 ++ 103 ++ 104 ++

Use what you can do to control asynchronous workflows.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

c++ - MATLAB .m file to .mex file using Matlab Compiler -