javascript - How to parse iframe on a website with CasperJS -
i want obtain informations on website iframe.
when parse website casperjs command :
casper.then(function() { casper.waitfor(function() { return this.withframe('mainframe', function() {}); }, function() { this.withframe('mainframe', function() { console.log(this.echo(this.gethtml())); }); }); }); my problem result, have content of 1 iframe only.
how can obtain result of iframe present on website?
casperjs doesn't provide function wait iframe load. however, can use waitforresource() step function wait iframe resource , act on it.
casper.waitforresource(function check(res){ var iframesrc = this.getelementattribute("iframe[name='mainframe']", "src"); return res.url.indexof(iframesrc) > -1; }, function(){ // success }); when resource received, can wait inside of iframe specific selector in order continue script iframe loaded:
casper.waitforresource(function check(res){ var iframesrc = this.getelementattribute("iframe[name='mainframe']", "src"); return res.url.indexof(iframesrc) > -1; }).withframe('mainframe', function(){ this.waitforselector("someselectorforanelement thatisloadedattheend", function(){ this.echo(this.gethtml()); }); }); casper.waitfor(function() { return this.withframe('mainframe', function() {}); }, function() { this code doesn't wait @ all. casperjs supports fluent api, can chain multiple step functions this:
casper.start(url) .then(function(){...}) .wait(3000) .then(function(){...}) .run(); this means result of withframe() casper object evaluated true check function. there no waiting going on.
console.log(this.echo(this.gethtml())); doesn't make sense, because casper.echo() prints console. use either
console.log(this.gethtml()); or
this.echo(this.gethtml()); but not both.
Comments
Post a Comment