javascript - CasperJS to loop again until to get data -



javascript - CasperJS to loop again until to get data -

i have function written in casperjs set info on textbox , click button extract info page.

var casper = require('casper').create({ verbose: false, pagesettings: { loadimages: false, loadplugins: false } }); casper.start("www.testsite.com", function(){ casper.thenevaluate(function(){ document.getelementsbyclassname('inputfield')[0].value="set data";//google.com document.queryselector('form[name="single_check_form"]').submit(); }).then(function(){ var info = this.evaluate(function(){ homecoming document.getelementsbytagname('tr')[13].childnodes[3].innerhtml.replace("- ","").replace("<br>",""); }); casper.echo("data found : "+data); }); });

the above function working file, in webpage after click 'string' or 'empty string' somethings 'null' result.

so, how loop until data?

you should utilize recursion, because casperjs steps can nested.

var info = null; function getdata(){ casper.thenopen("www.testsite.com").thenevaluate(function(){ document.getelementsbyclassname('inputfield')[0].value="set data";//google.com document.queryselector('form[name="single_check_form"]').submit(); }).then(function(){ info = this.evaluate(function(){ homecoming document.getelementsbytagname('tr')[13].childnodes[3].innerhtml.replace("- ","").replace("<br>",""); }); if (data == null) { getdata(); } }); } casper.start().then(getdata).then(function(){ casper.echo("data found : "+data); }).run();

javascript web-scraping phantomjs casperjs

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -