如何使用puppeteer-core,puppeteer使用本地Chrome,puppeteer下载失败问题

puppeteer由于众所周知的原因会下载失败,我们可以使用puppeteer-core配合本地的Chrome或者Chrome Canary来使用:
首先安装puppeteer-core和Carlo(会用到Carlo的find_chrome模块,可以在node_modules/carlo/lib/目录下找到)
//安装对应chrome@71对应的puppeteer
npm install puppeteer-core@chrome-71
//安装Carlo
npm i carlo
//或 yarn add carlo
不同版本的浏览器可以使用对应版本的puppeteer-core,以减少不兼容问题。
具体的puppeteer对应的Chrome版本查看:https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md 中的Releases per Chromium Version部分
const puppeteer = require('puppeteer-core');
//find_chrome模块来源于GoogleChromeLabs的Carlo,可以查看本机安装Chrome目录,详细请查看底部博客,

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/');
  /*
  	dosomeThing
  */

  await browser.close();
})();
以上代码部分来自下面的博客:

Web技术试炼地

chaos-fe

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一颗小行星!

恰饭ing

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值