您的位置:首页 > 编程语言 > Python开发

Python 爬虫学习笔记一: requests 模块

2017-11-08 11:27 736 查看

Python 爬虫学习笔记一: requests 模块

[转]Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求。


1. request 首页 : http://www.python-requests.org/en/master/

2. requests 安装过程 安装好之后,启动Python3.5.4 Shell ,

3. requests Quick Start

这个quick start 写的很详细, 基本就可以知道基本的request语法,另外通过 “Requests 安装过程”的链接, 可以得到很多其他详细信息

写一个简单的程序爬取某网站的信息,

首先应该先确定想要搜索的条件:



通过观察URL, 如果单纯的勾选, 则从上到下的URL增添依次为:

p21 , p22, p23….p27,b300to500 (100 是最低价,500是最高价)

a1,a2,a3…m80to100

l1,l2,l3 ….

f1,f2,f3,f4,f10

y1,y2,y3,y4,y5

c1,c2,c3

u2,u3

x1,x2,x3,x4,x5

o1,o3,o4

zcl1,zcl2,zcl3,zcl4

t1,t5,v2,v4

fg1,fg3,fg5,fg6,fg7,fg8,fg9

如果每项都选中的话,按照字母顺序排序。

通过爬取的内容观察,我感兴趣的信息全部保存在
<span class="info-col">
中,主要拉取这些信息就足够了。

<div class="info-table">
<div class="info-row">
<span class="info-col row1-text">
<svg><use xlink:href="#icon-house"></use></svg>
2室1厅 | 72.49平

| 中区/6层

| 朝南北

</span>
<div class="info-col price-item main">
<span class="total-price strong-num">300</span>
<span class="unit">万</span>
</div>
</div>
<div class="info-row">
<span class="info-col row2-text">
<svg><use xlink:href="#icon-map"></use></svg>
<a class="laisuzhou" target="_blank" href="/xiaoqu/5011000010872.html"><span title="水语人家">水语人家</span></a> |
<a href="/ershoufang/minhang/">闵行</a> |
<a href="/ershoufang/pujiang1/">浦江</a>

| 2010年建

</span>
<span class="info-col price-item minor">
单价41385元/平
</span>
</div>
</div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 爬虫