requests-html HTTPSConnectionPoolRead 超时 [英] requests-html HTTPSConnectionPoolRead timed out

查看:86
本文介绍了requests-html HTTPSConnectionPoolRead 超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试向此处发送请求使用 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)

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

I thought setting the user agent would fix the problem, but I am still receiving the error? Increasing the timeout hasn't done the trick either

推荐答案

你可以用 Async 做到这一点

You can do this with Async

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)

这篇关于requests-html HTTPSConnectionPoolRead 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆