import urllib.request
url = 'http://www.whatismyip.com.tw/'
# 创建一个包含代理IP的opener
proxy_support = urllib.request.ProxyHandler({'http':'223.96.90.216'})
opener = urllib.request.build_opener(proxy_support)
# 可以安装进默认环境
# urllib.request.install_opener(opener)
# 如果安装了直接执行以下urllib,request.urlopen()
response = urllib.request.urlopen(url)
# 如果没有安装,跳过以上语句执行opener.open()
# req = urllib.request.Request(url)
# response = opener.open(req)
html = response.read().decode('utf-8')
print(html)
Python urllib opener建立
最新推荐文章于 2023-07-12 09:57:17 发布