Python爬虫入门<五>—DebugLog

Python爬虫入门<五>——DebugLog

标签:DebugLog

DebugeLog

1.首先,我们先先来了解一下DebugLog是什么?
我们经常说的BUG就是错误,Debug就是调试错误,LOG代表日志,所以,,,DebugLog就是调试日志,这个可以帮助我们在运行程序的过程中打印日志,接下来,我们就开始开启DebugLog:
1.使用urllib.request.HTTPHandler()和urllib.request.HTTPSHandler()将debuglevel是指为1;
2.使用urllib.request.build_opener()创建自定义opener对象,使用1中的值作为对象的参数
3.urllib.request.install_opener()创建全局默认的opener对象,我们使用urlopen()的时候,就会使用opener对象。
4.继续后面操作
代码:

import urllib.request

httphd = urllib.request.HTTPHandler(debuglevel=1)
httpshd = urllib.request.HTTPSHandler(debuglevel=1)

opener = urllib.request.build_opener(httphd,httpshd)
urllib.request.install_opener(opener)
data = urllib.request.urlopen("http://www.baidu.com")

结果:

C:\Users\Administrator\PycharmProjects\untitled2\venv\Scripts\python.exe F:/python/python代码/venv/python入门五.py
send: b'GET / HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: www.baidu.com\r\nUser-Agent: Python-urllib/3.6\r\nConnection: close\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date header: Content-Type header: Transfer-Encoding header: Connection header: Vary header: Set-Cookie header: Set-Cookie header: Set-Cookie header: Set-Cookie header: Set-Cookie header: Set-Cookie header: P3P header: Cache-Control header: Cxy_all header: Expires header: X-Powered-By header: Server header: X-UA-Compatible header: BDPAGETYPE header: BDQID header: BDUSERID 
Process finished with exit code 0

说明日志正在打印,DebugLog成功开启了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值