Python设置IP代理

import requests


headers = {
            'Referer': 'https://www.baidu.com',  # 伪装成从CSDN博客搜索到的文章
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36'
            # 伪装成浏览器
        }
#设置代理ip
proxies = {
	"http":"http://115.159.31.195:8080"
}
params={
    'wd':'ip地址'
}
response = requests.request('get', "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=5&tn=98010089_dg&wd=IP%E5%9C%B0%E5%9D%80&oq=python%25E7%2588%25AC%25E8%2599%25AB%25E4%25B8%25AD%25E7%259A%2584ip%25E4%25BB%25A3%25E7%2590%2586%25E8%25AE%25BE%25E7%25BD%25AE&rsv_pq=823b58a500018356&rsv_t=7c6fTg5nHBZ1%2FD0Isvs0AhKi78NbBaZFMg%2FX%2B%2B9lEIwMcQJDUWhTLFBURNG00Zy1lh8&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=11&rsv_sug1=7&rsv_sug7=101&rsv_sug2=0&inputT=6885&rsv_sug4=6885",proxies = proxies,headers = headers,params=params)

print(response.text)
with open('ip.html','w',encoding='utf-8') as f:
    f.write(response.text)

你可能感兴趣的:(#,Python基础应用)