我一般都在pycharm终端里下载省事,pip install httpx
设置
client=httpx.Client(http2=True)
还需要安装 指令 pip install httpx[http2]
运行代码
import httpx
url='https://spa16.scrape.center/'
headers={
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62',
'referer': 'https://scrape.center/'
}
client=httpx.Client(http2=True) #使用http2.0
response_httpx=client.get(url,headers=headers)
print(response_httpx.text)
print(response_httpx.http_version) #查看使用什么传输协议
运行结果