PhantomJS
PhantomJs(使用QtWebKit内核)已经停止维护了
baidu.js
// 创建一个网页实例 var page = require('webpage').create(); // 加载页面 page.open('https://www.baidu.com/', function () { // 给网页截屏保存 page.render('baidu.png'); phantom.exit(); }) $ phantomjs baidu.js
Puppeteer(chrome headless)
文档:https://github.com/puppeteer/puppeteer
安装
$ npm i puppeteer
example.js
const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); // 设置视窗大小 await page.setViewport({ width: 1400, height: 800, }); // 打开页面 await page.goto("https://zhuanlan.zhihu.com/p/76237595"); // path: 截屏文件保存路径 await page.screenshot({ path: "example.png" ,fullPage: true }) await browser.close(); })();
SlimerJS
SlimerJS是基于火狐的浏览器引擎Gecko
Firefox. version: 53.0 to 59.0
下载地址:https://slimerjs.org/download.html
安装依赖
npm install slimerjs var page = require('webpage').create(); page.open("https://mp.weixin.qq.com/s/YHeEjam6lze8OgyiPBWorQ", function (status) { page.viewportSize = { width:1024, height:768 }; page.render('screenshot.png'); slimer.exit() }); $ npx slimerjs screenshot.js
参考