【问题标题】:requests-html HTTPSConnectionPoolRead timed outrequests-html HTTPSConnectionPoolRead 超时
【发布时间】:2019-06-20 17:31:22
【问题描述】:

尝试向here发送请求 使用requests-html

这是我的代码:

headers = {"User-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"}
session = HTMLSession()
while True:
   try:
       r = session.get("https://www.size.co.uk/product/white-fila-v94m-low/119095/",headers=headers,timeout=40)
       r.html.render()
       print(r.html.text)

   except Exception as e:
       print(e)

这是我收到的错误:

HTTPSConnectionPool(host='www.size.co.uk', port=443): Read timed out. (read timeout=40)

我认为设置用户代理可以解决问题,但我仍然收到错误消息?增加超时也没有成功

【问题讨论】:

  • 错误告诉你问题所在。 Read timed out. (read timeout=40) 增加timeout。这是一个超级慢的网站,需要更长的时间来加载。
  • @antfuentes87 感谢您的回复!我会增加超时并报告:)
  • 将超时设置为100000 仍然给出读取超时错误

标签: session web-scraping python-requests python-requests-html


【解决方案1】:

你可以用异步来做到这一点

from requests_html import AsyncHTMLSession

s = AsyncHTMLSession()
async def main():
    r = await s.get('https://www.size.co.uk/product/white-fila-v94m-low/119095/')
    await r.html.arender()
    print(r.content)

s.run(main)

【讨论】:

    猜你喜欢
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    相关资源
    最近更新 更多