requests_html TimeoutError:超过导航超时:超过9000 ms

时间:2020-08-24 15:13:53

标签: python python-requests python-requests-html

我想使用https://www.woorank.com/en/www/webmatrices.com抓取动态网站requests_html(即需要花费一些时间来加载-JAVASCRIPTED)。当它尝试下面的代码时,会弹出错误。 当前,我在PC上使用它,但是在服务器上使用它。 我不希望有任何硒推荐,因为我没有在服务器中安装java,因此可以在服务器中运行它。

from requests_html import HTMLSession
asession = HTMLSession()
headers = {
    'user-agent':'Mozilla/5.0',
    'x-requested-with': 'XMLHttpRequest'
}
r = asession.get('https://www.woorank.com/en/www/webmatrices.com', headers = headers)

file = open('newsite.html', 'w+')
file.write(str(r.html.render(timeout=9)))
file.close()

这是弹出的错误:

  File "C:\Users\Dell\AppData\Roaming\Python\Python38\site-packages\requests_html.py", line 512, in _async_render
    await page.goto(url, options={'timeout': int(timeout * 1000)})
  File "C:\Users\Dell\AppData\Roaming\Python\Python38\site-packages\pyppeteer\page.py", line 885, in goto
    raise error
pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 9000 ms exceeded.
enter code here

1 个答案:

答案 0 :(得分:0)

您只需要将render timeout参数增加到大于9的值即可。请尝试setInterval