Skip to content

Instantly share code, notes, and snippets.

@jwalsh
Created July 9, 2012 21:34
Show Gist options
  • Save jwalsh/3079134 to your computer and use it in GitHub Desktop.
Save jwalsh/3079134 to your computer and use it in GitHub Desktop.
var page = require('webpage').create(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: ' + phantom.scriptName + ' URL filename');
phantom.exit();
}
var start = new Date();
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 900, height: 600 };
page.onLoadStarted = function () {
var diff = new Date() - start;
console.log('Load: start: ' + diff);
};
page.onLoadFinished = function (status) {
var diff = new Date() - start;
console.log('Load: finished: ' + diff);
console.log('Page title is ' + page.evaluate(
function () {
return document.title;
}));
};
page.open(address,
function (status) {
console.log('Loading: ' + address);
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(
function () {
console.log('Loaded successfully...');
page.render(output);
phantom.exit();
}, 200);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment