1. 首页
  2. 编程语言
  3. Python
  4. 使用Python的ProxyHandler示例

使用Python的ProxyHandler示例

上传者: 2023-06-28 20:24:06上传 PY文件 438B 热度 12次

'''使用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

下载地址
用户评论