手机
当前位置:查字典教程网 >脚本专栏 >python >Python抓取百度查询结果的方法
Python抓取百度查询结果的方法
摘要:本文实例讲述了Python抓取百度查询结果的方法。分享给大家供大家参考。具体实现方法如下:#winpython2.7.ximportre,s...

本文实例讲述了Python抓取百度查询结果的方法。分享给大家供大家参考。具体实现方法如下:

#win python 2.7.x import re,sys,urllib,codecs xh = urllib.urlopen("http://www.baidu.com/s").read().decode('utf-8') rc = re.compile(r'<td class=f><h3><a.*?>(?P<first>.*?)</h3>',re.I) match = rc.finditer(xh) rcr = re.compile(r'<[^>]+>',re.I) f = codecs.open("xiaohei.txt", "w", "utf-8") for i in rc.finditer(xh): ss = i.group(0) s1 = rcr.sub('',ss) print (s1) f.write(s1) f.close()

希望本文所述对大家的Python程序设计有所帮助。

【Python抓取百度查询结果的方法】相关文章:

Python中使用中文的方法

Python使用代理抓取网站图片(多线程)

Python通过解析网页实现看报程序的方法

如何运行Python程序的方法

python抓取网页时字符集转换问题处理方案分享

python正则表达式修复网站文章字体不统一的解决方法

python解析json实例方法

python解决字典中的值是列表问题的方法

Python的函数嵌套的使用方法

vc6编写python扩展的方法分享

精品推荐
分类导航