爬取网站为https://cq.58.com/ershoufang/的重庆挂牌出售的全部二手房信息信息。爬取信息包括卖点、楼盘、楼盘地址、房屋户型、楼层、建筑年代、每平单价、房屋总价。
时间: 2024-01-19 20:04:41 浏览: 26
好的,您需要使用Python编写一个爬虫程序来爬取https://cq.58.com/ershoufang/网站上的重庆挂牌出售的全部二手房信息。以下是一个示例程序,您可以参考它完成您的任务:
```python
import requests
from bs4 import BeautifulSoup
url = "https://cq.58.com/ershoufang/"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"}
# 发送请求
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
# 解析网页内容
house_list = soup.find_all('div', {'class': 'property-content-title'})
for house in house_list:
# 获取卖点
sell_point = house.find('span', {'class': 'property-content-title-text'}).text.strip()
# 获取楼盘名称、地址
estate = house.find('a', {'class': 'property-content-title-link'}).text.strip()
address = house.find('p', {'class': 'property-content-excerpt'}).text.strip()
# 获取房屋户型、楼层、建筑年代
house_info = house.find('div', {'class': 'property-content-room'}).text.strip()
floor = house.find('div', {'class': 'property-content-floor'}).text.strip()
year = house.find('div', {'class': 'property-content-year'}).text.strip()
# 获取每平单价、房屋总价
price = house.find('div', {'class': 'property-content-price'}).text.strip()
total_price = house.find('div', {'class': 'property-content-total'}).text.strip()
# 打印结果
print("卖点:", sell_point)
print("楼盘名称:", estate)
print("地址:", address)
print("户型/楼层/年代:", house_info, floor, year)
print("每平单价:", price)
print("总价:", total_price)
print("=" * 50)
```
这段代码会输出每个二手房的卖点、楼盘名称、地址、房屋户型、楼层、建筑年代、每平单价和房屋总价。您可以根据需要对这些信息进行存储和处理。