-
-
Save julienb74/2157299 to your computer and use it in GitHub Desktop.
check google ads with phantomjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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