如何远程获取网页打印画面?使用linux/unix或php工具。用户输入页面地址,我想保存在服务器上的外观(作为图像)。
发布于 2011-11-03 17:41:23
您需要一个无头web浏览器(即您可以从命令行运行的浏览器,没有图形界面)。一种这样的可能性是PhantomJS,它使用webkit呈现引擎。
具体地说,您需要render() method。
在examples page上的渲染示例中,将以下代码另存为rasterize.js
var page = new WebPage(),
address, output, size;
if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 600, height: 600 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
}然后运行它:
phantomjs rasterize.js http://ariya.github.com/svg/tiger.svg tiger.pnghttps://stackoverflow.com/questions/7992526
复制相似问题