1、简介
在爬虫程序运行的时候,我们希望边运行边打印调试日志,此时,就需要开启DebugLog
2、应用
使用思路:
1、分别使用urllib.request.HTTPHandler()和urllib.request.HTTPSHandler()将debuglevel设置为1
2、使用urllib.request.build_opener()创建自定义的opener对象,并使用1中设置的值做为参数
3、用urllib.request.install_opener()创建全局默认的opener对象
4、爬取到的数据处理
# *-*coding:utf-8*-*
from urllib import request
# debuglog
http = request.HTTPHandler(debuglevel=1)
https = request.HTTPSHandler(debuglevel=1)
opener = request.build_opener(http,https)
request.install_opener(opener)
data = request.urlopen("http://www.baidu.com")
运行日志