为什么要使用httpx
requests模块不支持http2.0协议, 在访问使用http2.0协议的网站时, 就需要用到httpx
# 使用requests模块访问http2.0的网站, 会报错
import requests
url = 'https://spa16.scrape.center/'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
}
resp = requests.get(url=url, headers

本文介绍了为什么需要使用httpx模块,特别是在处理http2.0协议的网站时。httpx提供了与requests类似的API,同时支持http2.0和异步操作,通过示例展示了如何开启http2.0支持和查看协议版本。
最低0.47元/天 解锁文章
6545

被折叠的 条评论
为什么被折叠?



