Advertisement
Guest User

Untitled

a guest
Feb 27th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var casper = require("casper").create();
  3. var url = casper.cli.get(0);
  4.  
  5. var casper = require('casper').create({
  6.     verbose: true,
  7.     logLevel: "debug",
  8.         webSecurityEnabled: false
  9. });
  10.  
  11. casper.on('remote.message', function(msg) {
  12.     this.echo(msg);
  13. })
  14.  
  15. function getLinksFromIframes( callback ) {
  16.     var links = [];
  17.  
  18.     var iframes = this.evaluate( function() {
  19.         var iframes = [];
  20.         [].forEach.call(document.querySelectorAll("iframe"), function(iframe, i) { iframes.push( i ); });
  21.         return iframes;
  22.     });
  23.  
  24.     iframes.forEach( function( index ) {
  25.         this.withFrame(index, function() {
  26.             links = links.concat( this.getElementsAttribute( 'a', 'href' ) );
  27.             console.log("works: " + links);
  28.         });
  29.     });
  30.  
  31.     this.then(function(){
  32.         callback.call(this, links);
  33.     });
  34. }
  35.  
  36. casper.start(url, function () {
  37.     getLinksFromIframes.call(this, function(links){
  38.         thelinks = links;
  39.         console.log("Links: " + thelinks);
  40.     });
  41. })
  42. .then(function(){
  43.     console.log("Links later: " + thelinks);
  44. })
  45. .run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement