环境搭建

  1. apt install npm
  2. npm install -g n
  3. n stable
  4. node -v
  5. npm install puppeteer typescript @types/puppeteer

安装完后,保存下面代码到run.js

  1. const puppeteer = require('puppeteer');
  2. (async () => {
  3. const browser = await puppeteer.launch();
  4. const page = await browser.newPage();
  5. await page.goto('https://y.qq.com');
  6. await page.screenshot({path: './yqq.png'});
  7. browser.close();
  8. })();

运行

  1. node run.js

其他拓展:

docker在ubuntu下安装:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04

yarn:Try-puppeteer前置条件:
https://yarn.bootcss.com/docs/install.html#linux-tab

try-puppeteer:Docker环境:
https://github.com/ebidel/try-puppeteer