Skip to content

Instantly share code, notes, and snippets.

@LeeMendelowitz
Last active August 29, 2015 14:16
Show Gist options
  • Save LeeMendelowitz/0b9688cd3ac8e6a2fbed to your computer and use it in GitHub Desktop.
Save LeeMendelowitz/0b9688cd3ac8e6a2fbed to your computer and use it in GitHub Desktop.
Take a snapshot of a page with phantom JS

To run, download PhantomJS

From the terminal:

phantomjs snapshot.js > output.html
var system = require('system');
var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36';
var cur_url = "http://dcmetrometrics.com/dailyservicereport/2015_02_23";
var snapshot = function(my_page) {
system.stderr.write("SNAPSHOT!\n");
var content = page.content;
system.stdout.write(content);
phantom.exit();
};
system.stderr.write("opening pages...");
page.open(cur_url, function (status) {
if (status !== 'success') {
system.stderr.write('Unable to access network');
phantom.exit();
} else {
system.stderr.write("done opening page.");
setTimeout(function() {
snapshot();
phantom.exit();
}, 5000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment