Open YBFACC opened 4 years ago
使用npm安装npm i puppeteer。
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.
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
UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn /Applications/Chromium.app/ EACCES
更改路径 executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium'
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新手遇到的坑
安装puppeteer踩坑
使用npm安装
npm i puppeteer
。执行以下代码
报错
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路径
报错
UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn /Applications/Chromium.app/ EACCES
更改路径
executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium'
参考的解决方案
puppeteer新手遇到的坑