PhantomJS笔记,Node.js集成PhantomJS
转 https://www.linchaoqun.com/html/cms/content.jsp?menu=index&id=1511140432245
https://github.com/ariya/phantomjs
https://www.npmjs.com/package/phantom
https://github.com/amir20/phantomjs-node
PhantomJS
phantom:幽灵
一个看不见摸不着的浏览器
PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
PhantomJS抓取网页生成png
var page = require('webpage').create();page.open('http://www.linchaoqun.com', function(status) { console.log("Status: " + status); if(status === "success") { page.render('example.png'); } phantom.exit(); });
phantomjs hello.js
Node.js集成PhantomJS
npm install phantom --save
const phantom = require('phantom'); (async function() { const instance = await phantom.create(); const page = await instance.createPage(); await page.on('onResourceRequested', function(requestData) { console.info('Requesting', requestData.url); }); const status = await page.open('http://www.linchaoqun.com/'); const content = await page.property('content'); console.log(content); page.render('example.png'); await instance.exit(); })();