from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
def post_name():
web.find_element(By.XPATH,'/html/body/div[7]/section/div/div/div[2]/div/footer/button[2]').click()
web.find_element(By.XPATH,'//*[@id="Koan-via-HeaderController__input"]').send_keys(name,Keys.ENTER)
time.sleep(5)
def get_content():
div=web.find_elements(By.CLASS_NAME,'_8ssblpx')[1:]
for i in div:
introduction=i.find_element(By.CLASS_NAME,'_qrfr9x5').text
price=i.find_element(By.CLASS_NAME,'_18gk84h').find_elements(By.TAG_NAME,'span')[1].text
print(f'{introduction}\t{price}/晚')
print('---------------------------')
def get_next():
for i in range(14):
get_content()
web.find_element(By.XPATH, '//*[@id="site-content"]/div/div/div/div[3]/div/div/div/div[1]/nav/div/a[6]').click()
time.sleep(5)
if __name__ == '__main__':
web = webdriver.Chrome()
web.get('https://www.airbnb.cn/')
web.maximize_window()
name=input('请输入你要查询的地点:')
post_name()
get_next()
get_content()
|