代理操作
import requests
# 使用代理获取百度首页
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.57'
}
# 定义代理的字典
proxies = {
"http": "http://39.129.56.28:443",
"https": "http://39.129.56.28:443"
}
# 使用代理给服务器发送请求
response = requests.get("http://icanhazip.com/", proxies=proxies, headers=headers)
# 设置编码
# response.encoding = 'utf-8'
# 获取状态
print(response.status_code)
print(response.text)