puppeteer 是chrome 團隊提供的Headless chrome node api 庫,咱們能夠用來方便的進行chrome 操做,同時
能夠作好多事情(web 爬蟲,生成pdf,截圖。。。)node
注意合理上網git
npm i puppeteer --save
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage();
await page.goto('https://docs.getdbt.com/docs/introduction', {waitUntil: 'networkidle2'});
await page.screenshot({path: 'example.png',fullPage:true});
await page.pdf({path: 'hn.pdf', format: 'A4'});
await browser.close();
})();
截圖
github
puppeteer 仍是很強大的,2.0 也在規劃中,可是有破壞性的修改web
https://github.com/GoogleChrome/puppeteer
https://pptr.dev/chrome