手机
当前位置:查字典教程网 >脚本专栏 >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生成pdf文件的方法

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

python实现DNS正向查询、反向查询的例子

python每次处理固定个数的字符的方法总结

python调用shell的方法

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

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

Python的函数嵌套的使用方法

python实现监控linux性能及进程消耗性能的方法

精品推荐
分类导航