Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created August 13, 2012 06:49
Show Gist options
  • Save fengmk2/3337502 to your computer and use it in GitHub Desktop.
Save fengmk2/3337502 to your computer and use it in GitHub Desktop.
snapshot
var system = require('system');
var args = system.args;
var page = require('webpage').create(),
address, top, left, width, height, output;
if (args.length < 2 || args.length > 7) {
console.log('Usage: snapshot.js URL top left width height filename');
phantom.exit();
} else {
address = args[1];
var query = 40;
top = parseInt(args[2], 10);
left = parseInt(args[3], 10) + (1024 - 980) / 2;
width = args[4];
height = parseInt(args[5], 10);
output = args[6];
page.viewportSize = { "width": 1024, "height": 768 };
//left = 20;
//width = 984;
page.clipRect = { top: top, left: left, width: width, height: height };
page.onResourceReceived = function (response) {
if (response.url === address) {
if (response.status !== 200) {
console.log('fail');
phantom.exit();
}
page.onResourceReceived = null;
}
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('fail');
phantom.exit();
} else {
setTimeout(function () {
page.render(output);
console.log("success");
phantom.exit();
}, 200);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment