我想刮去“预订网站“网站,但我无法获取价格,因为我无法强制下面的代码在日期字段中选择日期,我使用了与发送城镇字段相同的方法来发送日期字段。 我将代码管理如下:
import re
import time
import csv
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
from bs4.element import Tag
CITIES=["Bordeaux,france"]
driver = webdriver.Chrome()
for city in CITIES:
driver.get("https://www.booking.com/")
driver.find_element_by_css_selector("#ss").send_keys(city) # Enter City Name
# Wait until autosuggestion come and click on first suggestion
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="frm"]/div[2]/div/div[1]/ul[1]/li[1]')))
driver.find_element_by_xpath('//*[@id="frm"]/div[2]/div/div[1]/ul[1]/li[1]').click()
check_in_time = datetime.fromtimestamp(int(time.time())).strftime("%Y-%m-%d")
check_out_time = datetime.fromtimestamp(int(time.time()) + 604800).strftime("%Y-%m-%d")
# Waits for Datetime widget and select check In date
try:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
(By.XPATH, '//*[@id="frm"]/div[3]/div/div[1]/div[1]/div[2]/div/div[2]/div[1]/div')))
except TimeoutException:
driver.find_element_by_xpath('//*[@id="frm"]/div[3]/div/div[1]/div[1]/div[2]').click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
(By.XPATH, '//*[@id="frm"]/div[3]/div/div[1]/div[1]/div[2]/div/div[2]/div[1]/div')))
table = driver.find_elements_by_xpath('//*[@id="frm"]/div[3]/div/div[1]/div[1]/div[2]/'
'div/div[2]/div[2]/div[3]/div/div/div[1]/table//td')
for x in table:
if x.get_attribute("data-id") and datetime.fromtimestamp(int(x.get_attribute("data-id")[:-3])).strftime(
"%Y-%m-%d") == check_in_time:
x.click()
# Waits for Datetime widget and select check Out date
### A voir
driver.find_element_by_xpath('//*[@id="frm"]/div[3]/div/div[1]/div[2]/div[2]/div/div[1]/div/div[2]').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, '//*[@id="frm"]/div[3]/div/div[1]/div[2]/div[2]/div/div[2]/div[1]/div')))
table = driver.find_elements_by_xpath('//*[@id="frm"]/div[3]/div/div[1]/div[2]/div[2]/div/div[2]/div[2]/'
'div[3]/div/div/div[1]/table//td')
for x in table:
if x.get_attribute("data-id") and datetime.fromtimestamp(int(x.get_attribute("data-id")[:-3])).strftime(
"%Y-%m-%d") == check_out_time:
x.click()
# Click Search Button
driver.find_element_by_class_name('sb-searchbox__button').click()
任何帮助都将不胜感激。在
函数
^{pr2}$select_date
:相关问题 更多 >
编程相关推荐