1. 程式人生 > >Debuglog

Debuglog

思路:

  1. 分別用urllib.request.HTTPHander()和urllib.request.HTTPSHander()將debuglevel設定為1
  2. 使用urllib.request.build_opener()建立自定義的opener物件,並使用1.中作為引數
  3. 用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("網址")