ProxyHandler要怎么实现代理IP使用?
发布时间:2019-12-03 15:04:51 来源:IP精灵
ProxyHandler要怎么实现代理IP?下面来一起看看IP精灵给大家带来的教程讲解,一起来看看代理IP的使用方面。
from urllib import request
#这个是没有使用代理的
# resp = request.urlopen('http://httpbin.org/ip')
# print(resp.read().decode("utf-8"))
#这个是使用了代理的
#1.使用ProxyHandler,传入构建一个Handler
#2.使用上面创建的Handler构建一个opener
#3.用opener去发送一个请求
handler = request.ProxyHandler({"http":"183.158.206.169:9000"})
opener = request.build_opener(handler)
req = request.Request("http://httpbin.org/ip")
resp = opener.open(req)
print(resp.read())
按照上面的步骤,我们就完成了代理IP在ProxyHandle的配置使用,是不是很简单呢?