Skip to content

Instantly share code, notes, and snippets.

@firedfox
Created March 14, 2012 17:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save firedfox/2037945 to your computer and use it in GitHub Desktop.
Save firedfox/2037945 to your computer and use it in GitHub Desktop.
find google ads with phantomjs
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]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment