微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python Requests_html:给我超时错误

如何解决Python Requests_html:给我超时错误

我正在尝试使用名为medium.com的库来抓取requests_html标题

我正在使用的代码在他人的PC上运行良好,但在我的PC上却不行。

原始代码如下:

from requests_html import HTMLSession

session = HTMLSession()
r = session.get('https://medium.com/@daranept27')
r.html.render()

x = r.html.find('a.eg.bv')
[print(elem.text) for elem in x]

它给了我pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 8000 ms exceeded.

这是完整的错误

Traceback (most recent call last):

  File "C:\Users\intel\Desktop\hackerrank.py",line 5,in <module>
    r.html.render()
  File "C:\Users\intel\AppData\Local\Programs\Python\python38\lib\site-packages\requests_html.py",line 598,in render
    content,result,page = self.session.loop.run_until_complete(self._async_render(url=self.url,script=script,sleep=sleep,wait=wait,content=self.html,reload=reload,scrolldown=scrolldown,timeout=timeout,keep_page=keep_page))
  File "C:\Users\intel\AppData\Local\Programs\Python\python38\lib\asyncio\base_events.py",line 616,in run_until_complete
    return future.result()
  File "C:\Users\intel\AppData\Local\Programs\Python\python38\lib\site-packages\requests_html.py",line 512,in _async_render
    await page.goto(url,options={'timeout': int(timeout * 1000)})
  File "C:\Users\intel\AppData\Local\Programs\Python\python38\lib\site-packages\pyppeteer\page.py",line 885,in goto

    raise error
pyppeteer.errors.TimeoutError: Navigation Timeout Exceeded: 8000 ms exceeded.

[Finished in 13.0s with exit code 1]

[shell_cmd: python -u "C:\Users\intel\Desktop\hackerrank.py"]
[dir: C:\Users\intel\Desktop]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\python38;C:\Users\intel\AppData\Local\Programs\Python\python38\Scripts\;C:\Users\intel\AppData\Local\Programs\Python\python38\;C:\MinGW\bin;C:\Users\intel\AppData\Local\Programs\Microsoft VS Code\bin]

我在自己的其中一个帖子上看到了一条评论,也看到了其他人的回答以重新运行它,然后它将起作用。我不明白为什么...

解决方法

您收到的错误表明您没有及时收到服务器的响应。

我在您的计算机(Ubuntu 18.04)上成功运行了您的代码,并得到了以下结果:

Seven Days -Between Life And Death
Have you ever encountered a fake friend? If So,Try These Simple Tips To Overcome it.
Does Anybody Ever Wonder Why He’s My Everything?
Ladies,Why Should You Treat Your Face Like The Coloring Books?
Listen,Girl,Aren’t You Curious How The Last Line Could Be This Hurtful?
The girl name “Rich”
She Lost Her Beloved Mother,But Why She Asserted that Loss Was Not Just A Loss sometimes?
You Used To Try This Lonely. Have You Ever Imagine The flavor You Tried To Eat it with Your Lover?
If You Have Siblings,You Won’t Comprehend this. Have You Ever Wonder How A Child Feels Like? This Is How It Perceives.
Is It Okay To Help A Stranger?
The Nightmare Was Always Considered A Bad Omen,But It Turned Incredible Differently.
If You’re A Woman Or Girl Who Loves To Wear Lipstick,Read This Poetry.
She Wants To Spread This Poetry For Every Girl Or Woman That Was Born Just Like The Way She Was.

您必须检查您的互联网连接。

或者,建议您以管理员模式运行空闲状态,然后通过idle重新运行代码。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。