python抓取中文页面并查找关键字页面

//首先,设置文件字符编码格式为UTF-8

#coding: UTF-8

import urllib
import chardet

total_cnt=29
target_str="顺受"

//判断目标字符串编码格式
print chardet.detect(target_str) 

for i in range(1, total_cnt+1):

        content=urllib.urlopen("http://bbs.tianya.cn/post-16-998474-%s.shtml" % (str(i))).read()

        ////判断网页的编码格式,如果不一样要进行编码格式的转换

        #print chardet.detect(content)
        if target_str in content:
                print "find target url, ind is %d" % (i)
        else:
                print "still not found"

你可能感兴趣的:(python抓取中文页面并查找关键字页面)