【发布时间】:2021-03-11 18:14:31
【问题描述】:
我正在使用 requests-html 并尝试渲染功能,但收效甚微。当我使用 python3.8 运行这个脚本时
#!/usr/bin/python3
from requests_html import HTML
file = "scrape/temp_file2.html"
with open(file) as html_file:
source = html_file.read()
html = HTML(html=source)
html.render()
match = html.find('#footer', first=True)
try:
print(match.hmtl)
except:
print('not found')
它会导致回溯:
python3 scrape/test1.py
Traceback (most recent call last):
File "scrape/test1.py", line 10, in <module>
html.render()
File "/home/pi/.local/lib/python3.8/site-packages/requests_html.py", line 586, in render
self.browser = self.session.browser # Automatically create a event loop and browser
File "/home/pi/.local/lib/python3.8/site-packages/requests_html.py", line 730, in browser
self._browser = self.loop.run_until_complete(super().browser)
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/home/pi/.local/lib/python3.8/site-packages/requests_html.py", line 714, in browser
self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
File "/home/pi/.local/lib/python3.8/site-packages/pyppeteer/launcher.py", line 306, in launch
return await Launcher(options, **kwargs).launch()
File "/home/pi/.local/lib/python3.8/site-packages/pyppeteer/launcher.py", line 147, in launch
self.proc = subprocess.Popen( # type: ignore
File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.8/subprocess.py", line 1702, 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/588429/chrome-linux/chrome'
铬文件是一个可执行文件:
ls -l /home/pi/.local/share/pyppeteer/local-chromium/588429/chrome-linux/chrome
-rwxr-xr-x 1 pi pi 214121928 Mar 9 17:21 /home/pi/.local/share/pyppeteer/local-chromium/588429/chrome-linux/chrome
如果我删除 html.render() 行,它可以正常工作(但不会呈现 javascript)。 有什么想法吗?
【问题讨论】:
-
如果您使用
file /home/pi/.local/share/pyppeteer/local-chromium/588429/chrome-linux/chrome,它是否将其识别为与您的 CPU 匹配的可执行文件? -
你说得对,可执行文件与 CPU 不匹配:文件 /home/pi/.local/share/pyppeteer/local-chromium/588429/chrome-linux/chrome ELF 64-bit LSB共享对象,x86-64,版本 1 (SYSV),动态链接,解释器 /lib64/ld-linux-x86-64.so.2,用于 GNU/Linux 3.2.0,未剥离 应该是,例如:文件/usr/local/bin/python3.8 python3.8:ELF 32 位 LSB 可执行文件,ARM,EABI5 版本 1 (SYSV),动态链接,解释器 /lib/ld-linux-armhf.so.3,用于 GNU/ Linux 3.2.0,BuildID[sha1]=11f271b583048eca129a464244876a525e5f92f0,未剥离。知道如何纠正它吗?
标签: python python-3.x python-requests python-requests-html