Debuglog
阿新 • • 發佈:2018-12-15
思路:
- 分別用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("網址")