javascript - Change the filepath to save the page content depending on the existence of a page element -


i downloaded many pages html casperjs, want separate them in 2 folders. files contains id="trie" , others not.

what can do, please?

this script

casper.repeat(j , function(){   casper.open(arrdata[i]); // arrdata[i] : contains url of file download   casper.wait(5000, function(){     file = 'pages/road/r_' + +'.html';     fs.write(file, casper.gethtml(), 'w');   });   i++; }); 

but want this

casper.repeat(j, function(){   casper.open(arrdata[i]);   if ("id=trie" exists in contains of arrdata[i] ){     file put pages/trie/...html   } else {     file put pages/road/...html   }   i++; }); 

you want use exists function:

var = 0; var fs = require('fs'); casper.repeat(j, function(){   (function(i){     casper.thenopen(arrdata[i], function(){       if (casper.exists("#trie")){         fs.write("pages/trie/"+i+".html", casper.gethtml());       } else {         fs.write("pages/road/"+i+".html", casper.gethtml());       }     });   })(i);   i++; }); 

note must done in step, otherwise run concurrency problems. in code open calls executed before first wait executed.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -