美文网首页
网络爬虫:urllib模块应用11--代理

网络爬虫:urllib模块应用11--代理

作者: 牛耀 | 来源:发表于2018-12-23 15:01 被阅读0次
from urllib import request

# ProxyHandler()目的:是为了设置代理,使用代理发送请求
# proxies:对应的是一个字典
# 代理有免费的(西刺、快代理。。。)
# 和收费的代理(西刺、快代理。。。阿步云)
#  私密代理,账号密码认证
proxies = {
    'http':'113.105.152.87:37238',
    'https':'61.128.208.94:3128',
}
handler = request.ProxyHandler(proxies=proxies)

# 自定义opener
opener = request.build_opener(handler)

url = 'http://httpbin.org/get'

response = opener.open(url)
print(response.status)
print(response.read().decode('utf-8'))

相关文章

网友评论

      本文标题:网络爬虫:urllib模块应用11--代理

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