请求\u html超时错误:超过导航超时:超过9000毫秒

2024-04-20 12:19:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用requests_html来抓取一个动态网站https://www.woorank.com/en/www/webmatrices.com(即需要时间来加载-JAVASCRIPTED)。当它尝试下面的代码时,出现了一个错误。 目前我正在我的电脑上使用它,但我将在我的服务器上使用它。 我不想要任何selenium推荐,因为我的服务器中没有安装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

Tags: https服务器comhtmlwww错误timeoutrequests