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技術試煉地
