Skip to content

Instantly share code, notes, and snippets.

@komljen
Last active December 29, 2015 23:59
Show Gist options
  • Save komljen/7746529 to your computer and use it in GitHub Desktop.
Save komljen/7746529 to your computer and use it in GitHub Desktop.
This script will load whole webpage and return processed html. Also it will skip Google Analytics (ga.js). Usage: phantomjs get.js http://www.example.com More info here: http://www.techbar.me/performance-testing-with-phantomjs/
var page = require('webpage').create(),
system = require('system'),
address;
address = system.args[1];
page.onResourceRequested = function (requestData, request) {
if ((/ga.js/gi).test(requestData['url'])) {
console.log('Skiping: ' + requestData['url']);
request.abort();
}
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var p = page.evaluate(function () {
return document.getElementsByTagName('html')[0].innerHTML
});
console.log(p);
}
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment