我试图让我的 RP 成为一些 Web 自动化任务的服务器,因此我安装了 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'
该代码仅在 headless 模式下启动 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())
我尝试安装 here 中的所有 Debian 依赖项并让 pypputeer 再次安装 chromium,就像第一次一样。但似乎没有什么可以解决这个错误。还有this Github post这似乎没有帮助。有谁知道可以做什么吗?
显然,解决方案是将代码中的 chromium 路径重定向到您知道正在运行的某个版本的 chromium。所以
whereis chromium-browser
然后:
browser = await launch(headless=True, executablePath='/usr/bin/chromium-browser') # where your chromium was, in my case /usr/bin/...
我是一名优秀的程序员,十分优秀!