为什么要使用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