Flight: Using Selenium Scraper to Find the Cheapest Flight!

Posted on Dec 25, 2019
The skills I demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

LinkedInGitHubEmail | Data | Web App

The goal of this project is to build a web scraper that performs searches on flight prices with flexible dates (up to 3 days before and after the dates you select first) for a particular destination. The program saves an excel with the results and sends an alert email with the quick stats with the best deals.

While most of us would agree that traveling is a great way to experience new cultures and broaden our perspectives, the process of searching for the best price for our buck is rather a tedious procedure. I eventually chose to scrape HotWire because of the lack of Recaptcha. The idea of the structure of the web scraper is more or less like this:

  • a function will start the bot, declaring the cities and dates we want to search
  • this function gets the first search results, sorted by “best” flights
  • another function will scrape the whole page, and output into an excel file
  • it will repeat step 2 and 3 for the “cheap” sort types
  • an email will be sent to you with a summary of the prices (cheapest and average)


As a start, I used Chrome driver as my web driver to open a blank Chrome tab and randint to make the bot sleep a random number of seconds between each search. To start getting prices and other information, I gathered all the XPaths to all the elements I wanted and used Python to select the cheapest results.

After inputting the travel destination in mind as well as the expected travel date, each desired result [airline, flight duration, layover(s) and layover duration, price] was scrapped and fetched using a series of for loops and printed into an excel file called flight data. The data are then re-read into Jupyter Notebook and the data was cleaned using regular expressions.

From the user front, the program prompts the users to declare the destination cities and the travel dates as inputs. From there, it will open the address in the HotWire string, which goes directly to the sort by “price” results page. The program will output the top 5 matrices with the cheapest flight prices and used the list of prices to calculate the average price of the 7-day travel range and highlight the minimum price as well. The result is then emailed to the user based on the HotWire searches. The code was tested using a Hotmail account, and the user can simply replace the information using their details if they were to utilize the program.


In conclusion, there are plenty of improvements can be made to the current program. I can code the program further so it will provide more travel options to the users [round trips, airline, flight class, etc], integrate the code with Twilio so the program will send out a text instead of email alert, figure a method to work around the ReCaptcha so the scraper can be applied to other search engines as well.

About Author

Lily Kuo

Liyi (Lily) is a Data Science Fellow at the New York City Data Science Academy with a Masters in Biomedical Engineering and Education. She is aspired to be a data scientist who executes data-driven strategies to increase efficiency,...
View all posts by Lily Kuo >

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI