Yuying Wu

puppeteer调研

July 10, 2018

Puppeteer Intro

Puppeteer金字塔

"Puppeteer Pyramid"

无需再通过Chrome的开发协议,写冗长复杂的代码,轻松调用Chrome API。

"puppeteer-devtools-protocol"

Puppeteer的使用场景。

"Puppeteer use case"

Demo - screenshot

setup

npm i puppeteer --save

demo

打开example.com,截屏,生成文件example.png

// screenshot.js
const puppeteer = require('puppeteer');

puppeteer.launch({
  headless: false
}).then(async browser => {
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
});

// run the demo
// node screenshot.js

"screenshot-puppeteer"

Youtube Video: “Intro of Puppeteer - Chrome Dev Summit 2017” “The power of Headless Chrome and browser automation (Google I/O ‘18)”