链家网杭州租房信息数据爬取+数据分析

参考https://mp.weixin.qq.com/s/vvZ2yBb2eMKP800LUPoAWg

需求分析


  • 过去一个月,全国热点城市的房租如脱缰野马。一线的房租同比涨了近20%。一夜醒来,无产青年连一块立锥之地都悬了。
    从2018下半年开始,租金海啸汹汹来袭,资本狂欢,官方默然,房东纠结,租客尖叫。这不是一方的过错,而更像是一场
    全社会的“集体谋杀作品”。最令人不安的是,过去房地产的那套玩法和上涨逻辑,今天正在转移到房租上。
  • 通过python获取某网站杭州的租房数据,来进行数据分析


页面分析


要爬取得字段

  • 1.标题 title
    title=html.xpath(‘.//li/div[@class=”info-panel”]/h2/a/@title’)[i].replace(“,”,” “)
  • 2.户型 room_type
    room_type=html.xpath(‘//div[@class=”list-wrap”]//li//div[@class=”where”]/span[@class=”zone”]/span/text()’)[i].replace(“\xa0\xa0”,”“)
  • 3.面积 meters
    m=html.xpath(‘//div[@class=”list-wrap”]//li//div[@class=”where”]/span[@class=”meters”]/text()’)[i].replace(“\xa0\xa0”,”“)
  • 4.建筑时间 time
    time=html.xpath(‘//div[@class=”list-wrap”]//li//div[@class=”con”]/text()[2]’)[i]
  • 5.所在楼层 floor
    floor=html.xpath(‘//div[@class=”list-wrap”]//li//div[@class=”con”]/text()[1]’)[i]
  • 6.价格 price
    price=html.xpath(‘//div[@class=”list-wrap”]//li//div[@class=”col-3”]/div[@class=”price”]/span/text()’)[i]
  • 7.楼层总高 tatal_floor
    tatal_floor=re.findall(‘(\d+)’,floor)[0]
  • 8.更新时间 price_pre
    price_pre=html.xpath(‘//div[@class=”price-pre”]/text()’)[i][:-2]
  • 9.具体位置 detail_place
    detail_place=re.findall(“(\w+)租房”,html.xpath(‘//div[@class=”con”]/a/text()’)[i])[0]


数据分析


数据获取


In [2]:
import requests
import re
from  lxml import etree


In [3]:
def get_html(url):
    headers={
        
        "user-agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"
    }
    r=requests.get(url,headers=headers)
    html=etree.HTML(r.text)
    for i in range(30):
        title=html.xpath('.//li/div[@class="info-panel"]/h2/a/@title')[i].replace(","," ")
        room_type=html.xpath('//div[@class="list-wrap"]//li//div[@class="where"]/span[@class="zone"]/span/text()')[i].replace("\xa0\xa0","")
        try:
            m=html.xpath('//div[@class="list-wrap"]//li//div[@class="where"]/span[@class="meters"]/text()')[i].replace("\xa0\xa0","")
            meters=re.findall('(\d+)',m)[0]
            meters=float(meters)

        except:
            meters=''
        meters=str(meters)
        time=html.xpath('//div[@class="list-wrap"]//li//div[@class="con"]/text()[2]')[i]
        floor=html.xpath('//div[@class="list-wrap"]//li//div[@class="con"]/text()[1]')[i]
        try:
            price=html.xpath('//div[@class="list-wrap"]//li//div[@class="col-3"]/div[@class="price"]/span/text()')[i]
        except:
            price=""
        tatal_floor=re.findall('(\d+)',floor)[0]
        floor = floor[:1]
        try:
            time=re.findall('(\d+)',time)[0]
        except:
            time=''
        price_pre=html.xpath('//div[&#
  • 0
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值