官网地址:http://phantomjs.org/
首先通过命令 npm install --save phantom
安装phantom 【本篇文章Node版本为6.X】

新建一个app.js文件

代码:
var phantom = require('phantom');
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
page.open("https://www.baidu.com").then(function(status) {
page.property('viewportSize', { width: 1920, height: 1080 });
page.render('./baidu.jpg').then(function() {
console.log('Page rendered');
ph.exit();
});
});
});
});
运行app.js:

我们可以看到 app.js同级目录多了一个baidu.jpg

双击打开效果

网友评论