Skip to content

Instantly share code, notes, and snippets.

@julienb74
Forked from firedfox/gist:2037945
Created March 22, 2012 09:10
Show Gist options
  • Save julienb74/2157266 to your computer and use it in GitHub Desktop.
Save julienb74/2157266 to your computer and use it in GitHub Desktop.

Revisions

  1. @firedfox firedfox created this gist Mar 14, 2012.
    29 changes: 29 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    var page = require('webpage').create();
    page.settings.loadImages = false;
    page.onConsoleMessage = function(msg) { console.log(msg); };

    page.onLoadFinished = function() {
    page.evaluate(function() {
    var getFrames = function(doc) {
    var frames = doc.querySelectorAll('iframe');
    for (var i = frames.length - 1; i >= 0; i--) {
    var fdoc = frames[i].contentWindow.document;

    if (!fdoc) {
    console.log('please add "--web-security=no" to phantomjs(1.5.0 and above) command-line and try again\n');
    return;
    }

    if (/googleads/.test(frames[i].src)) {
    console.log('found google ads: \n' + (fdoc.body.innerText || fdoc.querySelector('img').src + '\n'));
    } else {
    getFrames(fdoc);
    }
    }
    };
    getFrames(document);
    });
    phantom.exit();
    };

    page.open(phantom.args[0]);