用 Puppeteer 下载网页 pdf 版本

1
2
3
4
mkdir play_puppeteer && cd $_
yarn add puppeteer
emacs main.js
node main.js

main.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://www.baidu.com/', {
    waitUntil: 'networkidle2',
  });
  await page.pdf({ path: 'baidu.pdf', format: 'a4' });

  await browser.close();
})();

Layout of comment panels