思路:
- 分别用urllib.request.HTTPHander()和urllib.request.HTTPSHander()将debuglevel设置为1
- 使用urllib.request.build_opener()创建自定义的opener对象,并使用1.中作为参数
- 用urllib.request.install_opener()创建全局默认的opener对象,在使用urlopen()时,也会使用我们安装的opener对象
import urllib.request
httphd = urllib.request.HTTPHandler(debuglevel = 1)
httpshd = urllib.request.HTTPSHandler(debuglevel = 1)
opener = urllib.request.build_opener(httphd,httpshd)
urllib.request.installl_opener(opener)
data = urllib.request.urlopen("网址")