python - 在树莓派上运行 puppeteer 时出现 OSError
问题描述
我试图让我的 RP 成为一些网络自动化任务的服务器,所以我安装了python 3.7
pypputeer ( Googlel 的 puppeteer 的 Python 版本)。问题是我在我的 OSX 上顺利运行的代码在 PI 上给了我以下错误:
Traceback (most recent call last):
File "main.py", line 45, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "/usr/local/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
return future.result()
File "main.py", line 16, in main
browser = await launch(headless=True)
File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 311, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", line 169, in launch
**options,
File "/usr/local/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/home/pi/.local/share/pyppeteer/local-chromium/575458/chrome-linux/chrome'
该代码仅在无头模式下启动 chromium:
async def main():
browser = await launch(headless=True)
page = await browser.newPage()
await page.goto(URL_FOR_SCRAPING)
asyncio.get_event_loop().run_until_complete(main())
我尝试从这里安装所有 Debian 依赖项,并pypputeer
像第一次一样再次安装 chromium。但似乎没有什么可以解决这个错误。还有这个 Github 帖子似乎没有帮助。有谁知道可以做什么?
解决方案
Apparently the solution was to redirect chromium path in the code to some version of chromium you know is working. so
whereis chromium-browser
and then:
browser = await launch(headless=True, executablePath='/usr/bin/chromium-browser') # where your chromium was, in my case /usr/bin/...
推荐阅读
- javascript - 为什么winston 3.x 只记录一个参数?
- statistics - 有人可以解释如何对重复的横截面数据进行回归吗?
- dictionary - 运行时未检测到切片上的竞争
- reactjs - 如何将 Spring Boot 与 React 集成
- docker - 如何在现有的 docker swarm 中生成交互式容器?
- reactjs - React Table 如何添加/更改单个单元格
- r - 闪亮的 DT 表中的 unbindalll 问题
- c++ - 编译 woff2 时出现错误“需要 libbrotli”
- java - 如何从用户输入数组中调用某些信息
- firebase - Flutter - firebase_analytics 请求权限