Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

安装puppeteer踩坑 #28

Open
YBFACC opened this issue Jul 15, 2020 · 0 comments
Open

安装puppeteer踩坑 #28

YBFACC opened this issue Jul 15, 2020 · 0 comments
Labels
Hole 踩坑

Comments

@YBFACC
Copy link
Owner

YBFACC commented Jul 15, 2020

安装puppeteer踩坑

使用npm安装npm i puppeteer

执行以下代码

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

报错 Error: Could not find browser revision 768783. Run "npm install" or "yarn install" to download a browser binary.

需要手动安装Chromium

下载地址:https://download-chromium.appspot.com/

然后更改代码指向Chromium.app路径

const puppeteer = require('puppeteer')

;(async () => {
  const browser = await puppeteer.launch({
    executablePath: '/Applications/Chromium.app',
    headless: false
  })
  const page = await browser.newPage()
  await page.goto('https://example.com')
  await page.screenshot({ path: 'example.png' })

  await browser.close()
})()

报错 UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn /Applications/Chromium.app/ EACCES

更改路径 executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium'

const puppeteer = require('puppeteer')

;(async () => {
  const browser = await puppeteer.launch({
    executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
    headless: false
  })
  const page = await browser.newPage()
  await page.goto('https://example.com')
  await page.screenshot({ path: 'example.png' })

  await browser.close()
})()

参考的解决方案

puppeteer新手遇到的坑

@YBFACC YBFACC added the Hole 踩坑 label Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hole 踩坑
Projects
None yet
Development

No branches or pull requests

1 participant