puppeteer由于众所周知的原因会下载失败,我们可以使用puppeteer-core配合本地的Chrome或者Chrome Canary来使用:
首先安装puppeteer-core和Carlo(会用到Carlo的find_chrome模块,可以在node_modules/carlo/lib/目录下找到)
npm install puppeteer-core@chrome-71
npm i carlo
不同版本的浏览器可以使用对应版本的puppeteer-core,以减少不兼容问题。
具体的puppeteer对应的Chrome版本查看:https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md 中的Releases per Chromium Version部分
const puppeteer = require('puppeteer-core');
const findChrome = require('./node_modules/carlo/lib/find_chrome');
(async () => {
let findChromePath = await findChrome({});
let executablePath = findChromePath.executablePath;
console.log(executablePath)
const browser = await puppeteer.launch({
executablePath,
headless: false
});
const page = await browser.newPage();
await page.goto('http://www.woleigequ.net/');
await browser.close();
})();
以上代码部分来自下面的博客:
Web技术试炼地
