Python Selenium + Datepicker请点击

Python Selenium + Datepicker请点击,第1张

Python Selenium + Datepicker请点击

关于此日历的一件棘手的事情是,您首先需要将鼠标悬停在特定的日期,然后重新定位活动的日期并单击它。这是一个有效的实现方式,它选择第一个可用的开始和结束日期并打印计算出的价格:

from selenium import webdriverfrom selenium.webdriver import ActionChainsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECdriver = webdriver.Firefox()driver.maximize_window()wait = WebDriverWait(driver, 10)url = 'https://www.homeaway.pt/arrendamento-ferias/p1418427a?uni_id=1590648'driver.get(url)# pick start datestart_date = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".quotebar-container input[name=startDateInput]")))start_date.click()first_available_date = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ui-datepicker-div td.full-changeover > a")))ActionChains(driver).move_to_element(first_available_date).perform()driver.find_element_by_css_selector("#ui-datepicker-div td.full-selected.full-changeover > a").click()# pick end date (TODO: violates DRY principle, refactor!)end_date = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".quotebar-container input[name=endDateInput]")))end_date.click()first_available_date = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#ui-datepicker-div td.full-changeover > a")))ActionChains(driver).move_to_element(first_available_date).perform()driver.find_element_by_css_selector("#ui-datepicker-div td.full-selected.full-changeover > a").click()# get the calculated priceprice = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".price-quote .price-total")))print(price.text)driver.close()

目前,它选择

20/04/2016
23/04/2016
并打印
180€

希望能有所帮助。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5639018.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存