📅  最后修改于: 2023-12-03 15:29:39.583000             🧑  作者: Mango
Bot Idealista是一个基于Python编写的Web自动化机器人,用于在Idealista网站上搜索出售或出租房屋的信息。
python main.py
# 导入模块
import time
import csv
from selenium import webdriver
# 启动Chrome浏览器
driver = webdriver.Chrome('/path/to/chromedriver')
# 登录Idealista
driver.get('https://www.idealista.com/')
driver.find_element_by_css_selector('.icon-profile').click()
time.sleep(1)
driver.find_element_by_name('email').send_keys('your_idealista_email')
driver.find_element_by_name('password').send_keys('your_idealista_password')
driver.find_element_by_css_selector('.submit-form-login').click()
# 搜索房屋信息
driver.find_element_by_css_selector('.opt-sale').click()
driver.find_element_by_css_selector('.location').send_keys('Madrid')
driver.find_element_by_css_selector('.property-type').click()
driver.find_element_by_css_selector('.property-type .flat').click()
driver.find_element_by_css_selector('.search-button').click()
# 解析房屋信息并存储到CSV文件中
houses = driver.find_elements_by_css_selector('.item')
for house in houses:
address = house.find_element_by_css_selector('.item-link').text
price = house.find_element_by_css_selector('.price').text
area = house.find_element_by_css_selector('.area').text
bedrooms = house.find_element_by_css_selector('.rooms').text
house_type = house.find_element_by_css_selector('.details').text
with open('houses.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([address, price, area, bedrooms, house_type])
# 关闭浏览器
driver.quit()
以上是一个简单的Bot Idealista示例,你可以根据自己的需求进行修改和扩展。