不使用代理
import requests url0= headers = { User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.42 } res=requests.get(url0,headers=headers) print(baidu:,res.status_code)使用代理 注意https的代理走http
import requests url1= headers = { User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.42 } proxies = { https: :8001,# v2只提供了http的端口,这里https也是用http代理 http: :8001 } res=requests.get(url = url1,proxies = proxies,headers=headers) print(google:,res.status_code)