python爬虫使用代理

from urllib import request

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

#使用代理
#1.使用ProxyHandler构建一个hander
handler = request.ProxyHandler({
"HTTP":"182.35.84.11:9999"
})
#2.使用上面的hander构建一个opener
opener = request.build_opener(handler)
#3.使用opener去发送一个请求
resp = opener.open(url)
print(resp.read())
http://httpbin.org/ip
访问该网址可以返回你的ip地址。
posted @ 2020-03-22 15:23  渴望成为大佬的菜鸡  阅读(577)  评论(0)    收藏  举报