用于读取爬虫后的文件

来源:互联网 发布:知乎 加拿大ee 编辑:程序博客网 时间:2024/06/15 17:21
<pre name="code" class="python"># coding: utf-8'''Created on 2014-7-24@author: Administrator'''import urllib2from urllib2 import Requestimport reimport sysdef p(f):    print '%s.%s(): %s' % (f.__module__, f.__name__, f())# 返回当前系统所使用的默认字符编码p(sys.getdefaultencoding)req=Request('http://www.qiushibaike.com/article/62599902?list=hot&s=4689411')req.add_header('User-Agent', 'aa')response = urllib2.urlopen(req)html = response.read()#print htmlmyItems = re.findall('<div.*?class="content".*?title="(.*?)">(.*?)</div>',html,re.S)print  myItemsfor i in myItems:    #myItems是list集合    for j in range(len(i)):   #i是一个集合    len(i)为2  j的值为0和1        print i[j]                             
当一起打印的时候 中文就会有乱码,  分开迭代的读取的话 就会正常打印中文,很奇怪
    


                                             
0 0