Skip to content

Instantly share code, notes, and snippets.

@tamimibrahim
Forked from julienb74/gist:2157299
Created July 5, 2014 02:17
Show Gist options
  • Save tamimibrahim/dc5d70d06cc6cc1714d5 to your computer and use it in GitHub Desktop.
Save tamimibrahim/dc5d70d06cc6cc1714d5 to your computer and use it in GitHub Desktop.
var page = require('webpage').create();
page.settings.loadImages = false;
page.onConsoleMessage = function(msg) { console.log(msg); };
var pageUrl = 'http://www.bloggersentral.com/2010/08/how-put-add-adsense-on-blogger.html';
var num = 0;
var max = 2;
page.onLoadFinished = function() {
var text = page.evaluate(function() {
var sDoc = document.getElementById('aswift_1').contentWindow.document;
var xDoc = sDoc.getElementById('google_ads_frame2').contentWindow.document;
if (xDoc) {
return xDoc.body.innerText || xDoc.querySelector('img').src + '\n';
}
});
if (!text) {
console.log('please add "--web-security=no" to phantomjs(1.5.0 and above) command-line and try again');
phantom.exit(1);
}
if (num <= max) {
console.log('google ads ' + (num++) + ':\n' + text);
page.open(pageUrl + '?' + Math.random());
} else {
phantom.exit();
}
};
page.open(pageUrl + '?' + Math.random());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment