当前位置:   article > 正文

python爬取二手房网站数据,进行全国房价数据分析_爬取求房网

爬取求房网

概要

` 提示:这里我们采用PyCharm 2023.2.1

整体架构流程

分析网站
获取网站数据
提取我们想要的数据
保存想要的数据

分析网站

我们打开二手房价网站,例如(58同城:https://quanguo.58.com/ershoufang/?PGTID=0d100000-0221-8af0-e247-a41467723324&ClickID=4)
在这里插入图片描述

F12,打开管理员模式,进入查看相应元素,并找到数据接口
在这里插入图片描述

打开PyCharm

创建项目编写程序

import requests
from bs4 import BeautifulSoup
import pandas as pd

url = 'https://www.58.com/ershoufang/'
response = requests.get(url)
html = response.text
soup = BeautifulSoup(html, 'html.parser')

tbimg = soup.find_all('table', class_='tbimg')
data = []

for table in tbimg:
    cleft = table.find_all('tr')
    for row in cleft:
         name = row.find('a', class_='t').string
         price = row.find('b').string
         data.append([ name, price])

df = pd.DataFrame(data, columns=['name','price'])
df.to_csv('全国房价信息.csv', index=False, encoding='utf-8')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/192545
推荐阅读
相关标签
  

闽ICP备14008679号