Showing posts with label Headless browser. Show all posts
Showing posts with label Headless browser. Show all posts

Saturday, February 13, 2016

Phantom JS: Creating PNG Image File of the Specified URL

Creating PNG image file of the specified URL

pagerender.js:
var page = require('webpage').create(),
  system = require('system'),
  address;

if (system.args.length <= 2) {
  console.log('Usage: pagerender.js <some URL> <image name>');
  phantom.exit();
}

address = system.args[1];
image = system.args[2];

page.open(address, function(status) {
  console.log("Status: " + status);
  if(status === "success") {
    page.render(image);
  }
  phantom.exit();
});

Command:

$ phantomjs pagerender.js http://smashingtheory.blogspot.com test.png

Headless Browser: PhantomJS

PhantomJS