Python抓取百度查询结果的方法

yipeiwu_com5年前Python爬虫

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

#win python 2.7.x
import re,sys,urllib,codecs
xh = urllib.urlopen("http://www.baidu.com/s?q1=123&rn=100").read().decode('utf-8') 
rc = re.compile(r'<td class=f><h3 class="t"><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+mongodb数据抓取详细介绍

分享点干货!!! Python数据抓取分析 编程模块:requests,lxml,pymongo,time,BeautifulSoup 首先获取所有产品的分类网址: def s...

Python中Scrapy爬虫图片处理详解

下载图片 下载图片有两种方式,一种是通过 Requests 模块发送 get 请求下载,另一种是使用 Scrapy 的 ImagesPipeline 图片管道类,这里主要讲后者。 安装...

python抓取网站的图片并下载到本地的方法

实例如下所示: #!/usr/bin/python # -*- coding: UTF-8 -*- import re import urllib,urllib2; #通过url获取...

Python爬虫包BeautifulSoup学习实例(五)

本文为大家分享了Python爬虫包BeautifulSoup学习实例,具体内容如下 BeautifulSoup 使用BeautifulSoup抓取豆瓣电影的一些信息。 # -*- c...

python使用tornado实现简单爬虫

本文实例为大家分享了python使用tornado实现简单爬虫的具体代码,供大家参考,具体内容如下 代码在官方文档的示例代码中有,但是作为一个tornado新手来说阅读起来还是有点困难的...