Brand new to coding, currently working on my first project, and I've hit a roadblock. I'm attempting to use ChromeDriver + Selenium to submit flight data into the ITA Matrix flight search, wait, and then screenshot the resulting "Monthly Price Chart".
My code may not be pretty (yet) but it works... EXCEPT Flight prices found by ChromeDriver + Selenium are completely different from those found by a manual search with same parameters on 'regular' chrome. The culprit? For some reason, on Selenium, ITA Matrix automatically limits results to a single airline, as observed here: Different results when using Selenium + Python Here's my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-infobars')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--incognito')
chrome_options.add_argument('--disable-plugins-discovery')
chrome_options.add_argument('--start-maximized')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path="chromedriver.exe")
driver.delete_all_cookies()
print("Chrome Browser Launched")
url = 'http://matrix.itasoftware.com'
origin = 'Toronto Lester B. Pearson International, ON, Canada'
destination = 'San Francisco International, CA'
depart_date = '09/30/18'
stay_length = "8-14"
airlines = "AIRLINES AC AA UA"
driver.get(url)
driver.get_screenshot_as_file("before_.png")
#Locate and Input Origin Airport
Origin_Input = driver.find_element_by_id("cityPair-orig-0")
Origin_Input.send_keys(origin)
time.sleep(3)
Origin_Input.send_keys(Keys.RETURN)
#Locate and Input Destination Airport
Destination_Input = driver.find_element_by_id("cityPair-dest-0")
Destination_Input.send_keys(destination)
time.sleep(3)
Destination_Input.send_keys(Keys.RETURN)
#Check Box for Lowest Fares Calendar
driver.find_element_by_id("gwt-uid-168").click()
#Locate and Input Departure Date
Depart_Input = driver.find_element_by_id("calDate-0")
Depart_Input.send_keys(depart_date)
time.sleep(3)
Depart_Input.send_keys(Keys.TAB)
#Locate and Input Stay Length
Depart_Input = driver.find_element_by_id("calStay-0")
Depart_Input.send_keys(stay_length)
time.sleep(3)
#Submit
Depart_Input.send_keys(Keys.RETURN)
#waits for page to load
time.sleep(45)
driver.get_screenshot_as_file("after.png")
print('done!')
#driver.quit()
I've even tried using the advanced controls option to force-feed specific airline AITA codes into the search.. to no avail.
My best guess: website is detecting automation, and limiting results to one airline (primary carrier for origin country).
Other things I've tried: - incognito mode - disable plugins - disable extensions - start maximized - firefox w. geckodriver - delete cookies - modify chomedriver.exe to remove document variable as per Can a website detect when you are using selenium with chromedriver?
Obviously, I'm still learning, so I'm struggling to figure out my next move.. Any help greatly appreciated!