直接学习:https://edu.csdn.net/course/play/24756/280661
urllib库-ProxyHandler处理器
1、代理原理:在请求的目的网站之前,先请求代理服务器,然后让代理服务器去请求目的网站,代理服务器拿到目的网站的数据后,再转发给我们代码。
2、http://httpbin.org:这个服务站可以方便查询http请求的一些参数
3、在代码中使用代理示例:
# 使用代理
# 步骤
from urllib import request
url = 'http://httpbin.org/ip'
# 使用ProxyHandler,传入代理构建一个handler
handler = request.ProxyHandler({'http':'125.108.127.162:9000'})
# 使用上面的handler构建一个opener
opener = request.build_opener(handler)
# 使用opener去发送一个请求
res= opener.open(url)
print(res.read())