Here is the source code about obtain a snapshot of a website by using phantomJS.
var webPage = require("webpage"), address, filename, height, width; // generate webPage object var page = webPage.create(); // generate one page var system = require("system"); // generate system object to obtain parameters var args = system.args; // get the number of input parameters console.log("number is " + args.length); if(args.length !== 5){ // if the number of parameters is not correct exit console.log("the correct format is: address filename height width"); phantom.exit(); } console.log(args[0]); address = system.args[1]; output = system.args[2]; height = system.args[3]; width = system.args[4]; console.log(address + " " + output + " " + height + " " + width); page.viewportSize = {height:height, width:width}; // get the size of snapshot page.open(address, function start(status){ console.log(status); if(status === "success"){ // conduct the snapshot operation page.render(output); } phantom.exit(); // exit the programme
Get a snapshot by using phantomJS
原文地址:http://blog.csdn.net/worldmakewayfordream/article/details/45071829