from urllib import request,parse
url = "https://www.baidu.com/s?wd=ip"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'}
# 创建一个请求对象
req = request.Request(url=url,headers=headers)
# 创建一个handler
handler = request.ProxyHandler({"http":'122.241.88.79:15872'})
# 创建一个opener携带handler
opener = request.build_opener(handler)
# 用opener发起请求
res = opener.open(req)
with open("ip.html",'wb') as fp:
fp.write(res.read())
使用代理服务器发起请求
猜你喜欢
转载自blog.csdn.net/weixin_42819119/article/details/89478752
今日推荐
周排行