手机
当前位置:查字典教程网 >脚本专栏 >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实现DNS正向查询、反向查询的例子

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

python回调函数的使用方法

python逐行读取文件内容的三种方法

Python实现全局变量的两个解决方法

python生成器的使用方法

python抓取网页中的图片示例

Python中使用中文的方法

Python批量修改文件后缀的方法

精品推荐
分类导航