美文网首页
12.代理设置

12.代理设置

作者: 学飞的小鸡 | 来源:发表于2018-10-31 20:59 被阅读0次
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)








相关文章

网友评论

      本文标题:12.代理设置

      本文链接:https://www.haomeiwen.com/subject/mpsztqtx.html