I have been practicing my web-scraping skills recently and came across this fantastic piece by Fábio Neves: If you like to travel, let Python help you scrape the best cheap flights!
Instead of scraping the 'Kayak' site like Fábio, I decided to try and create a bot which would scrape the Ryanair site.
My approach:
I take a users input for their 'airport of departure'. I then select the 'From' text-box which prompts a dropdown list to appear. This dropdown list contains 234 locations.
city_from = input('From which city? ') #Takes users input
The next step I was trying to implement was to find the match for the users input with the options in the dropdown list. And the proceed to click that matching option.
elements_list = driver.find_elements_by_xpath('//div [@class="core-list-ref"]') ##Finds all Elements/Cities in the dropdown list
list_pos = [value for value in elements_list].index(str(city_from)) #Finds the value(city name) for each element in the dropdown list and tries to locate the position of the inputed 'airport of departure' in the list.
elements_list[list_pos].click() #I then try to select this option.
However...
It seems that not all 234 cities appear when I use the following code:
driver.find_elements_by_xpath('//div [@class="core-list-ref"]')
Only the first 79 appear Aalborg-Genoa, the other cities seem to be 'hidden'. I have found that when I manually scroll down to the bottom of the dropdown list, and try to re-run the code they appear.
So I then tried to implement .move_to_element(element), to make the bot scroll down to the last airport in the dropdown list. But this still only allows me to scroll as far as the 79th airport (Genoa). This makes my bot crash when the user inputs airports like 'Zurich'.
This is my first attempt at scraping. How can I overcome this issue, or is there a better way to select an 'airport of departure'. Please let me know if you need any more details.

