小编tgr*_*af2的帖子

Requests-html 导致 OSError: [Errno 8] 调用 html.render() 时执行格式错误

我正在使用 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')
Run Code Online (Sandbox Code Playgroud)

它会导致回溯:

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 …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-requests python-requests-html

6
推荐指数
1
解决办法
2489
查看次数