博主介绍:✌全网粉丝10W+,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业项目实战6年之久,选择我们就是选择放心、选择安心毕业✌
> 想要获取完整文章或者源码,或者代做,拉到文章底部即可与我联系了。点击查看作者主页,了解更多项目!
感兴趣的可以先收藏起来,点赞、关注不迷路,大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助同学们顺利毕业 。
1、毕业设计:2025年计算机专业毕业设计选题汇总(建议收藏)✅
2、最全计算机专业毕业设计选题大全(建议收藏)✅
技术栈:
Python语言、django框架、requests库、安居客二手房数据、数据库、Echarts可视化、HTML
(1)房屋信息可视化大屏分析
(2)后台数据管理
(3)数据采集
import time
import requests
import parsel
import csv
from bs4 import BeautifulSoup
with open('安居客.csv', mode='a', encoding='utf-8', newline='') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(['标题', '户型', '面积', '朝向', '楼层', '年份', '小区名称', '小区地址', '小区标签', '总价', '单价'])
def is_null(str_):
try:
str_ = str_.strip()
except:
str_ = ''
return str_
for page in range(1, 100): # 51
url = f'https://beijing.anjuke.com/sale/p{page}/?from=navigation'
# url = f'https://chongqing.anjuke.com/sale/p{page}/?from=navigation'
# 1. 发送请求
response = requests.get(url=url, headers=headers)
# 2. 获取数据
html_data = response.text
# 3. 解析数据
# 网页开发基础
# html(网页元素存储..) css(负责好看) js(动态效果)
#
select = parsel.Selector(html_data)
# soup = BeautifulSoup(html_data, 'html.parser') # 新增
divs = select.css('.property-content')
# print(html_data);break; # 不要执行
# 小区地址
correct_addresses = select.css('.property-content-info-comm-address')
for div in divs:
# .property-content-title-name 标题
标题 = is_null(div.css('.property-content-title-name::text').get())
# .property-content-info:nth-child(1) .property-content-info-text:nth-child(1) span 户型
户型s = div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(1) span::text').getall()
户型 = ' '.join(户型s)
# .property-content-info:nth-child(1) .property-content-info-text:nth-child(2) 面积
面积 = is_null(div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(2)::text').get())
# .property-content-info:nth-child(1) .property-content-info-text:nth-child(3) 朝向
朝向 = is_null(div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(3)::text').get())
# .property-content-info:nth-child(1) .property-content-info-text:nth-child(4) 楼层
# 楼层 = is_null(div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(4)::text').get())
floor_text = div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(4)::text').get()
# 使用is_null函数处理采集到的数据,如果没有数据则设置为空字符串
楼层 = is_null(floor_text)
# .property-content-info:nth-child(1) .property-content-info-text:nth-child(5) 年份
年份 = is_null(div.css('.property-content-info:nth-child(1) .property-content-info-text:nth-child(5)::text').get())
# .property-content-info:nth-child(2) .property-content-info-comm-name 小区名称
小区名称 = is_null(div.css('.property-content-info:nth-child(2) .property-content-info-comm-name::text').get())
# .property-content-info:nth-child(2) .property-content-info-comm-address 小区地址
# 小区地址 = is_null(div.css('.property-content-info:nth-child(2) .property-content-info-comm-address::text').get()) #原始
# 采集地址信息
address_spans = div.css('.property-content-info-comm-address span::text').getall()
小区地址 = ' '.join(address_spans)
# .property-content-info:nth-child(3) span 小区标签
小区标签s = div.css('.property-content-info:nth-child(3) span::text').getall()
小区标签 = ' '.join(小区标签s)
# .property-price .property-price-total .property-price-total-num 总价
总价 = is_null(div.css('.property-price .property-price-total .property-price-total-num::text').get())
# .property-price .property-price-average 每平方米的价格
单价 = is_null(div.css('.property-price .property-price-average::text').get())
print(标题, 户型, 面积, 朝向, 楼层, 年份, 小区名称, 小区地址, 小区标签, 总价, 单价)
# 4. 保存数据
with open('安居客.csv', mode='a', encoding='utf-8', newline='') as f:
csv_writer = csv.writer(f)
# print(标题, 户型, 面积, 朝向, 楼层, 年份, 小区名称, 小区地址, 小区标签, 总价, 单价)
csv_writer.writerow([标题, 户型, 面积, 朝向, 楼层, 年份, 小区名称, 小区地址, 小区标签, 总价, 单价])
time.sleep(1)
✌感兴趣的可以先收藏起来,点赞关注不迷路,想学习更多项目可以查看主页,大家在毕设选题,项目代码以及论文编写等相关问题都可以给我留言咨询,希望可以帮助同学们顺利毕业!✌
由于篇幅限制,获取完整文章或源码、代做项目的,拉到文章底部即可看到个人联系方式。
点赞、收藏、关注,不迷路,下方查看获取联系方式