python-快速使用urllib爬取网页(7-DebugLog)
来源:互联网 发布:八皇后问题答案java 编辑:程序博客网 时间:2024/06/11 08:52
有时我们希望在程序运行的过程中,边运行边打印调试日志信息,此时需要开启DeugLog
如何开启DebugLog那?
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-8import urllib.requesthttphd = 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")
通过上面代码,我们可以从执行结果中看到开启了DebugLog
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.0 200 OK\r\n'header: Server header: Cache-Control header: Pragma header: Content-Type header: Content-Encoding header: Content-Length header: Set-Cookie Process finished with exit code 0
阅读全文
0 0
- python-快速使用urllib爬取网页(7-DebugLog)
- python-快速使用urllib爬取网页(1)
- python-快速使用urllib爬取网页(4-GET)
- python-快速使用urllib爬取网页(5-POST)
- python-快速使用urllib爬取网页(6-代理服务器)
- python-快速使用urllib爬取网页(8-URLError)
- python-快速使用urllib爬取网页(小结)
- python-快速使用urllib爬取网页(2-Headers属性)
- python-快速使用urllib爬取网页(3-超时异常)
- 01爬虫---快速使用Urllib爬取网页
- python urllib爬取网页编码问题
- Python爬虫实例(4)-用urllib、re和正则表达式爬取网页图片
- python 使用selenium+urllib爬取淘宝MM照片
- 使用selenium等待网页加载完成,lxml解析网页,利用urllib爬取图片
- python urllib, urllib2实现登陆和简单爬取网页(个人坑点笔记)
- 使用DebugLog
- Python urllib 爬取基金数据
- python用urllib爬取百度
- finereport价格
- 蒙特卡罗模拟
- BZOJ3211 花神游历各国 【树状数组 + 并查集】
- hadoop安装问题---datanode无法启动
- finereport8.0破解jar
- python-快速使用urllib爬取网页(7-DebugLog)
- 程序员的五种不同寻常的特质
- finereport 破解版
- 云的安全 VS 云内的安全
- cad 2010 64位
- FineReporte9.0完美破解原理浅谈 微信 移动开发注册破解
- Struts的常用标签<%@ taglib prefix="s" uri="/struts-tags"%>
- 分割回文串 II
- 最新Android平台架构