首页 > Web开发 > 详细

Get a snapshot by using phantomJS

时间:2015-04-16 12:30:16      阅读:333      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!