我多次尝试手动下载 headless 浏览器以及其他一些尝试,但错误仍然存在。运行 Linux Mint。
(node:25262) UnhandledPromiseRejectionWarning: Error: Browser is not downloaded. Run "npm install" or "yarn install"
at ChromeLauncher.launch (/home/oem/web-scraping/puppetering/node_modules/puppeteer/lib/Launcher.js:236:15)
(node:25262) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25262) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
代码如下:
#!/usr/bin/node
const puppeteer = require('puppeteer');
async function scrape() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://ratings.fide.com/top.phtml?list=men');
const [ele] = page.$x('//*[@id="main-col"]/table[2]/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/a')
const name = await ele.getProperty('text')
console.log(name)
};
scrape()
最佳答案
我已经以 root 身份使用全局标志安装了 puppeteer。然后,我以用户身份启动了一个项目,并遇到了与您相同的问题。
在项目中运行 npm install puppeteer --save
并作为用户触发 Chromium 的下载,并解决了此错误。
不知道为什么 pupeeter 的全局安装没有触发相同的依赖项。
关于javascript - 为什么在 Linux 上运行简单的 puppeteer 脚本时会出现 "Browser is not downloaded"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60327735/