Get a snapshot by using phantomJS

使用PhantomJS获取网页快照
本文介绍了一个使用PhantomJS获取指定网站快照的脚本实例。该脚本接收网址、输出文件名及快照尺寸等参数,并通过PhantomJS的webPage模块创建页面对象,设置视窗大小并打开指定网址,最终生成图片快照。

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






评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值