DEV Community

Alom Dev
Alom Dev

Posted on

Getting Google Flights prices into a spreadsheet

Google Flights is the best flight search there is, and it has no public API. Google shut down the old QPX Express
API years ago, so if you want flight prices in a spreadsheet or a script, you either pay for a travel data provider
or you read what the Google Flights page shows.

I built a scraper for the second option, using the same Google Travel data I already used for a hotel price tool.
Here's what it does and a few things I ran into.

Three things people actually want

When I looked at what people ask for, it boiled down to three jobs:

  1. Every flight for a route and date, with price, airline, times, stops and layovers. Basically the results page as a table.
  2. The cheapest day to fly. Google's date grid shows a price for each departure date. That's the most useful view for anyone flexible on dates, and it's one request for about two months of prices.
  3. Alerts. Run it every day and only hear about flights whose price changed.

Things I didn't expect

City names and multi-airport cities. People type "New York", "NYC" or "JFK,EWR", not airport codes. Google's own
search rejects some of those codes, so the scraper resolves names and city codes to airports first.

Prices were the same everywhere I tested. I expected the country and IP to change fares, like hotel prices do.
Across US, Ukrainian, German and Indian connections the prices came back identical; only the currency and the
language of names changed. That may not hold for every airline, but it held in all my tests.

Google refuses a fair share of requests. Roughly a quarter to a third of connections get refused for flight
searches. The fix that worked was boring: switch to a new connection right away, and after a few refusals fall back
to the normal results page, which has the same data. In the end no route failed in my test runs.

Layovers are where the detail is. The interesting fields aren't the price, they're the layovers: which airport,
how long, and whether you have to change airports. A 50-minute connection with an airport change is a very
different trip from a 2-hour one in the same terminal.

Using it

Disclosure: this is my Google Flights Scraper on Apify. You can run
it from the Apify website without code and download CSV or Excel, or call it from Python.

Every flight from New York to London, cheapest first:

{ "origin": "JFK,EWR", "destination": "LHR", "departureDate": "+45", "sortBy": "price", "maxResults": 50 }
Enter fullscreen mode Exit fullscreen mode

Cheapest day to fly over the next two months, round trip with a 7-day stay:

{ "mode": "calendar", "origin": "BER", "destination": "BCN", "departureDate": "+7", "returnDate": "+14", "calendarDays": 60 }
Enter fullscreen mode Exit fullscreen mode

Price alerts on a schedule:

{ "origin": "WAW", "destination": "LIS", "departureDate": "+40", "returnDate": "+47", "onlyNewSinceLastRun": true, "monitorName": "waw-lis" }
Enter fullscreen mode Exit fullscreen mode

It costs $0.50 per 1,000 flights on Apify's free plan ($0.25 on bigger plans) and $0.20 per 1,000 calendar dates. A
whole route usually comes to a fraction of a cent.

If you need hotels for the same trip, there's a Google Hotels scraper
built on the same data.

Top comments (0)