指定小区名字 惠飞大厦
时间: 2023-11-03 07:05:40 AIGC 浏览: 106
好的,为了指定小区名字为“惠飞大厦”,我们需要在发送请求时设置相应的请求参数。下面是修改后的代码示例:
```python
import requests
from bs4 import BeautifulSoup
# 设置请求头,模拟人类操作
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.3'}
# 设置请求参数
url = 'https://wx.zu.ke.com/zufang/'
params = {
'page': 1,
'per': 20,
'keyword': '惠飞大厦'
}
# 发送请求
response = requests.get(url, headers=headers, params=params)
soup = BeautifulSoup(response.text, 'html.parser')
# 解析页面内容,获取租房信息
houses = soup.find_all('div', class_='content__list--item')
for house in houses:
title = house.find('a', class_='content__list--item--aside')['title']
price = house.find('span', class_='content__list--item-price').text.strip()
print(title, price)
```
这个示例代码可以爬取贝壳无锡站关键词为“惠飞大厦”的租房信息,并打印出房源标题和价格。你可以根据自己的需求修改请求参数、解析内容等部分,来获取更多的信息。
阅读全文
相关推荐









