标签:允许 代理服务 分享图片 文件 log handler uri tps jpg
# coding:utf-8
# 爬虫使用代理IP
from urllib import request,error
if __name__ == '__main__':
# 0.设置测 ip 的地址
url = "http://2018.ip138.com/ic.asp"
# 1.设置代理 ip,获取方法参照:https://www.cnblogs.com/xpwi/p/9600727.html
proxy = {'http':'189.201.142.129:57815'}
# 2.创建ProxyHandler
proxy_handler = request.ProxyHandler(proxy)
# 3.创建Opener
opener = request.build_opener(proxy_handler)
# 4.安装Opener
request.install_opener(opener)
# 下面再进行访问url就会使用代理服务器
try:
rsp = request.urlopen(url)
html = rsp.read().decode('GBK')
print(html)
except error.HTTPError as e:
print(e)
except Exception as e:
print(e)
标签:允许 代理服务 分享图片 文件 log handler uri tps jpg
原文地址:https://www.cnblogs.com/xpwi/p/9610984.html