PhantomJS笔记,Node.js集成PhantomJS

转 https://www.linchaoqun.com/html/cms/content.jsp?menu=index&id=1511140432245

http://phantomjs.org/

https://github.com/ariya/phantomjs

https://www.npmjs.com/package/phantom

https://github.com/amir20/phantomjs-node

 

phantomjs-logo.png

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();
})();

 

版权声明:本文为it-tsz原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/it-tsz/p/12028919.html