毕业设计 大数据房价数据分析及可视化 – python 房价分析

文章目录

🧿 选题指导, 项目分享:

https://gitee.com/dancheng-senior/project-sharing-1/blob/master/%E6%AF%95%E8%AE%BE%E6%8C%87%E5%AF%BC/README.md

1 课题背景

房地产是促进我国经济持续增长的基础性、主导性产业。如何了解一个城市的房价的区域分布,或者不同的城市房价的区域差异。如何获取一个城市不同板块的房价数据?
本项目利用Python实现某一城市房价相关信息的爬取,并对爬取的原始数据进行数据清洗,存储到数据库中,利用pyechart库等工具进行可视化展示。

2 数据爬取

2.1 爬虫简介

网络爬虫是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。爬虫对某一站点访问,如果可以访问就下载其中的网页内容,并且通过爬虫解析模块解析得到的网页链接,把这些链接作为之后的抓取目标,并且在整个过程中完全不依赖用户,自动运行。若不能访问则根据爬虫预先设定的策略进行下一个 URL的访问。在整个过程中爬虫会自动进行异步处理数据请求,返回网页的抓取数据。在整个的爬虫运行之前,用户都可以自定义的添加代理,伪 装 请求头以便更好地获取网页数据。
爬虫流程图如下:

毕业设计 大数据房价数据分析及可视化 - python 房价分析
实例代码

import requests
response = requests.get("http://httpbin.org/get")
print( response.status_code )
print( response.text )

2.2 房价爬取

累计爬取链家深圳二手房源信息累计18906条

  • 爬取各个行政区房源信息;
  • 数据保存为DataFrame;

相关代码

from bs4 import BeautifulSoup
import pandas as pd
from tqdm import tqdm
import math
import requests
import lxml
import re
import time

area_dic = {'罗湖区':'luohuqu',
            '福田区':'futianqu',
            '南山区':'nanshanqu',
            '盐田区':'yantianqu',
            '宝安区':'baoanqu',
            '龙岗区':'longgangqu',
            '龙华区':'longhuaqu',
            '坪山区':'pingshanqu'}

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36',
           'Referer': 'https://sz.lianjia.com/ershoufang/'}

sess = requests.session()
sess.get('https://sz.lianjia.com/ershoufang/', headers=headers)

url = 'https://sz.lianjia.com/ershoufang/{}/pg{}/'

def re_match(re_pattern, string, errif=None):
    try:
        return re.findall(re_pattern, string)[0].strip()
    except IndexError:
        return errif

data = pd.DataFrame()

for key_, value_ in area_dic.items():

    start_url = 'https://sz.lianjia.com/ershoufang/{}/'.format(value_)
    html = sess.get(start_url).text
    house_num = re.findall('共找到 (.*?) 套.*二手房', html)[0].strip()
    print('💚{}: 二手房源共计「{}」套'.format(key_, house_num))
    time.sleep(1)

    total_page = int(math.ceil(min(3000, int(house_num)) / 30.0))
    for i in tqdm(range(total_page), desc=key_):
        html = sess.get(url.format(value_, i+1)).text
        soup = BeautifulSoup(html, 'lxml')
        info_collect = soup.find_all(class_="info clear")

        for info in info_collect:
            info_dic = {}

            info_dic['area'] = key_

            info_dic['title'] = re_match('target="_blank">(.*?)

Original: https://blog.csdn.net/HUXINY/article/details/126536509
Author: DanCheng-studio
Title: 毕业设计 大数据房价数据分析及可视化 – python 房价分析

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/671546/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球