使用Python的ProxyHandler示例

上传:impatient_14063 浏览: 7 推荐: 0 文件:py 大小:438B 上传时间:2023-06-28 20:24:06 版权申诉

'''使用Python的ProxyHandler示例'''

'''示例代码:'''

import urllib.request

url = "http://www.baidu.com/"

proxy = {"http":"127.0.0.1:8888"}

创建Handler处理器对象pro_hand

= urllib.request.ProxyHandler(proxy)

创建自定义opener对象

opener = urllib.request.build_opener(pro_hand)

opener对象open方法发请求

req = urllib.request.Request(url)

res = opener.open(req)

print(res.read().decode("utf-8"))

'''示例代码:'''

import urllib.request

url = "http://www.baidu.com/"

proxy = {"http":"127.0.0.1:8888"}

创建Handler处理器对象pro_hand

= ur

上传资源
用户评论