python
文章平均质量分 56
两步一脚印
这个作者很懒,什么都没留下…
展开
-
python3 urllib使用debug输出
python2.7.5中使用debug输出,可以采用如下方式:import urllib2 httpHandler = urllib2.HTTPHandler(debuglevel=1) httpsHandler = urllib2.HTTPSHandler(debuglevel=1) opener = urllib2.build_opener(httpHandler, https原创 2015-03-25 11:34:18 · 2271 阅读 · 1 评论 -
python 正则表达式贪婪模式与非贪婪模式
之前未接触过正则表达式,今日看python网络爬虫的源码,里面一行正则表达式匹配的代码初看之下,不是很理解,代码如下:myItems = re.findall('<div.*?class="content".*?title="(.*?)">(.*?)</div>',unicodePage,re.S)“.*?”这种匹配方式,按理解应该是匹配任意字符0个或多个(re.S模式,“.”可以匹配“\n”),但原创 2015-03-26 12:00:00 · 20392 阅读 · 0 评论 -
python3 使用urllib.request模块,关于bytes和string的那些事
python 3.4.2 使用urllib.request模块获取网页内容,虽说知道要注意编解码的问题,但有些细节还是不清楚,终于碰到了TypeError的错误:TypeError:can't use a string pattern on a bytes-like object知道是字节和字符使用错误,但是问题在哪儿呢?只好敲代码问问了。import urllib.requesturl = 'ht原创 2015-03-26 14:22:11 · 7530 阅读 · 0 评论 -
UnicodeEncodeError: ‘gbk’ codec can’t encode character
python抓取重庆大学图书馆主页“http://lib.cqu.edu.cn/newversion/index.htm”,网页编码为"UTF-8"工具:python 3.4.2,windows平台源码如下:from urllib import request, parse url = 'http://lib.cqu.edu.cn/newversion/index.htm原创 2015-03-24 20:35:03 · 1184 阅读 · 0 评论