from urllib import request
import requests
url = "https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&tn=baidu&wd=ip&oq=ip&rsv_pq=b254df33000238fe&rsv_t=caee8Radj5kHT5OB1roVV9axqOakQtWZzVH9BYWRWLXkJtyQBHfRRlcDylg&rqlang=cn&rsv_enter=0&rsv_sug3=1&rsv_sug1=1&rsv_sug7=100&prefixsug=ip&rsp=0&rsv_sug4=1224"
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
}
# 创建一个请求对象
req = request.Request(headers=headers,url=url)
# 配置代理
# h = request.ProxyHandler({"https":"113.200.56.13:8010"})
# 创建一个opener携带代理handler
# opener = request.build_opener(h)
# res = opener.open(req)
res = requests.get(url=url,headers=headers,proxies={"https":"113.200.56.13:8010"})
with open("ip.html",'wb') as fp:
fp.write(res.content)
网友评论