Get a snapshot by using phantomJS
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。