Using Selenium Scraper to Find the Cheapest Flights!

Lily Kuo
Posted on Dec 25, 2019

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

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 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws 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 Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R 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 Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp