Python爬虫爬取链家网上的房源信息练习

本文介绍了如何使用Python爬虫从链家网上抓取房源信息,包括识别网页源代码、正则表达式匹配、数据解析、数据存储到Excel以及爬虫的伪装技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 一  

原链接:用Python爬虫爬取链家网上的房源信息_shayebuhui_a的博客-CSDN博客_python爬取链家

打开链家网页:https://sh.lianjia.com/zufang/  :用F12以页面中元素进行检查,点击左上角的小箭头,得到相关信息。在这个页面可以通过将鼠标悬浮在相关信息上,可以得到其源代码

 我们可以发现网页中包含浦东-川沙-园西小区的源代码为:

 

<a target="_blank" href="/https/blog.csdn.net/zufang/pudong/">浦东</a>
<a href="/https/blog.csdn.net/zufang/jinqiao/" target="_blank">川沙</a>
<a title="园西小区" href="/https/blog.csdn.net/zufang/c5011000007323/" target="_blank">园西小区</a>

使用正则表达式获取网页信息的语句可以写为:

#区域
findplace1 = re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">(.*)</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang.*" target="_blank" title=".*">.*</a>')  #创建正则表达式对象,表示规则(字符串的模式)
 
findplace2= re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">(.*)</a>-<a href="/https/blog.csdn.net/zufang.*" target="_blank" title=".*">.*</a>')
 
findplace3 = re.compile(r'<a href="/https/blog.csdn.net/zufang/.*" target="_blank">.*</a>-<a href="/https/blog.csdn.net/zufang/.* target="_blank">.*</a>-<a h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值