<div class="det"><span>房源详情</span></div>给这个代码加一个弹窗信息
时间: 2023-07-09 12:18:14 浏览: 34
您可以通过在这个代码中添加JavaScript代码来实现一个弹窗信息。以下是一种实现方式:
```html
<div class="det"><span onclick="alert('这是房源详情')">房源详情</span></div>
```
在这个代码中,我们将`<span>`标签中的`onclick`属性设置为`alert('这是房源详情')`。当用户点击“房源详情”时,就会弹出一个带有“这是房源详情”消息的弹窗。
您可以根据需要更改弹窗中的消息,也可以使用其他JavaScript代码来实现更复杂的弹窗。
相关问题
写一个用python爬虫安居家二手房列表的代码
好的,以下是一个用 Python 爬取安居客二手房列表的示例代码,你可以参考一下:
```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://xa.anjuke.com/sale/'
response = requests.get(url, headers=headers)
html = response.text
# 解析网页内容
soup = BeautifulSoup(html, 'html.parser')
house_list = soup.find_all('li', class_='list-item')
# 遍历房源信息并输出
for house in house_list:
title = house.find('div', class_='house-title').a.text.strip()
price = house.find('span', class_='price-det').text.strip()
area = house.find('div', class_='details-item').span.text.strip()
address = house.find('span', class_='comm-address').text.strip()
print(title, price, area, address)
```
以上代码可以爬取安居客西安二手房列表的标题、价格、面积和地址等信息,并进行输出。你可以根据自己的需求进行扩展和修改。值得注意的是,爬虫行为需要遵守相关法律法规和网站规定,不得用于非法用途。
import requests from bs4 import BeautifulSoup url = 'https://nantong.anjuke.com/sale/chongchuan/?from=HomePage_TopBar' # 获取网页内容 response = requests.get(url) html = response.content.decode('utf-8') # 解析网页内容 soup = BeautifulSoup(html, 'html.parser') house_list = soup.find_all('li', {'class': 'list-item'}) # 遍历房源信息 for house in house_list: # 房型 house_type = house.find('div', {'class': 'house-details'}).find_all('span')[0].text.strip() # 面积 area = house.find('div', {'class': 'house-details'}).find_all('span')[1].text.strip() # 小区 community = house.find('div', {'class': 'house-details'}).find_all('span')[2].text.strip() # 区域地点 location = house.find('div', {'class': 'house-details'}).find_all('span')[3].text.strip() # 总价 total_price = house.find('span', {'class': 'price-det'}).text.strip() # 每平方单价 unit_price = house.find('span', {'class': 'unit-price'}).text.strip() # 输出采集的数据 print('房型:', house_type) print('面积:', area) print('小区:', community) print('区域地点:', location) print('总价:', total_price) print('每平方单价:', unit_price) print('')为基础完成对数据进行清洗、处理:将面积、总价、每平方单价中的单位去除,并将数据转换为浮点型,将区域地点中的区和路名去除,仅保留中间的区域(例;取“崇川-北大街-幸福大道”中的“北大街”)。输出结果。
import requests
from bs4 import BeautifulSoup
url = 'https://nantong.anjuke.com/sale/chongchuan/?from=HomePage_TopBar'
response = requests.get(url)
html = response.content.decode('utf-8')
soup = BeautifulSoup(html, 'html.parser')
house_list = soup.find_all('li', {'class': 'list-item'})
for house in house_list:
house_type = house.find('div', {'class': 'house-details'}).find_all('span')[0].text.strip()
area = house.find('div', {'class': 'house-details'}).find_all('span')[1].text.strip()[:-2] # 去除单位
community = house.find('div', {'class': 'house-details'}).find_all('span')[2].text.strip()
location = house.find('div', {'class': 'house-details'}).find_all('span')[3].text.strip().split('-')[1] # 取区域
total_price = float(house.find('span', {'class': 'price-det'}).text.strip()[:-1]) # 去除单位并转换为浮点型
unit_price = float(house.find('span', {'class': 'unit-price'}).text.strip()[2:-4]) # 去除单位并转换为浮点型
print('房型:', house_type)
print('面积:', float(area))
print('小区:', community)
print('区域地点:', location)
print('总价:', total_price)
print('每平方单价:', unit_price)
print('')