提问人:Yamar Lyons 提问时间:11/10/2023 最后编辑:ShawnYamar Lyons 更新时间:11/10/2023 访问量:26
硒价格刮擦学校决赛。程序打开,但不输入任何信息
Selenium Price Scraping for school final. Program opens but does not type in any information
问:
Python 程序运行没有错误,但是当程序打开 Expedia 时,它不会在离开框中输入任何内容。它像它应该的那样进入盒子,但几秒钟后它点击并关闭了页面。
leaving_from = flight_info['Departure']
going_to = flight_info['Arrival']
trip_date = flight_info['Date']
#Go to Expedia
driver.get( "https://expedia.com")
#Click on Flights
#The flight_xpath represent the flight button on expedia
flight_xpath ="//a[@class='uitk-tab-anchor' and @aria-controls='search_form_product_selector_flights' and @role='tab' and @data-toggle='tab' and span[@class='uitk-tab-text' and text()='Flights']]"
flight_element = WebDriverWait(driver,5).until(
EC.presence_of_element_located((By.XPATH, flight_xpath))
)
flight_element.click()
time.sleep(0.2)
#Click on One-Way. IBecause it is easier this way.
oneway_xpath = "//a[@class='uitk-tab-anchor' and @aria-controls='FlightSearchForm_ONE_WAY' and @aria-selected='false' and @role='tab' and @data-toggle='tab' and span[@class='uitk-tab-text' and text()='One-way']]"
one_way_element = WebDriverWait(driver,5).until(
EC.presence_of_element_located((By.XPATH, oneway_xpath))
)
one_way_element.click()
time.sleep(0.9)
#Part 1: Flying From, Flying To, Departure Date, Return Date
#********************** Complete Leaving From Portion **********************
leaving_from_xpath = "//button[@aria-label='Leaving from' and @data-stid='origin_select-dialog-trigger']"
leaving_from_element = WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.XPATH, leaving_from_xpath))
)
leaving_from_element.clear
leaving_from_element.click()
time.sleep(1)
leaving_from_element.send_keys(leaving_from)
time.sleep(4) #Need this otherwise it will be too fast for the broswer
leaving_from_element.send_keys(Keys.DOWN, Keys.RETURN)
#********************** Complete Leaving From Portion **********************
我试图在括号周围加上一个括号,但这让它变得不那么开放。leaving_from_element.clear
答: 暂无答案
评论