0

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

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

4

1 回答 1

0

您可以使用异步执行此操作

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-08-23T18:49:23.730 回答