环境搭建
apt install npm
npm install -g n
n stable
node -v
npm install puppeteer typescript @types/puppeteer
安装完后,保存下面代码到run.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://y.qq.com');
await page.screenshot({path: './yqq.png'});
browser.close();
})();
运行
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