码迷,mamicode.com
首页 > Web开发 > 详细

Get a snapshot by using phantomJS

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

标签:phantomjs   automation   

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

标签:phantomjs   automation   

原文地址:http://blog.csdn.net/worldmakewayfordream/article/details/45071829

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!