DEV Community

Cover image for How to Scrape Google Flights
Noraina Nordin for SerpApi

Posted on • Originally published at serpapi.com

How to Scrape Google Flights

Google Flights is Google's free flight search service, part of the Google Travel platform. It aggregates flights from multiple airlines so travelers can search by departure and destination, compare prices across carriers, track fares, and book tickets in one place.

That aggregated data is exactly what makes Google Flights worth scraping. If you want to build or research flight prices, routes, and availability, scraping Google Flights gives you a rich, continuously updated data source, and SerpApi's Google Flights API lets you pull it as structured JSON in Python, JavaScript, or in any programming language of your choice without maintaining your own scraper.

Google Flights User Interface

Google Flights User Interface

Who Needs the Scraped Google Flights Data?

Travel agencies and online travel businesses use it for market analysis and competitive intelligence. They can track competitors' pricing strategies, route popularity, and demand trends. With that visibility, they can adjust their own fares and offers to stay competitive.

Developers use it to build flight comparison platforms, fare trackers, and AI travel assistants. All of these need live prices, routes, and availability. The API supplies that data on demand, so there's no fragile in-house flight scraper to build or maintain.

Available Data on the Google Flights API

Before scraping, it helps to understand the structure of the data returned.

Flight Results

A response is organized into two main arrays:

  • best_flights : The top options for your search criteria. However, note that these results are not always returned by Google Flights itself.
  • other_flights : The remaining options, in the same structure.

Each entry contains a list of individual flights with:

  • Departure and arrival airports and times
  • Duration, airplane model, airline, travel class, and flight number
  • Layover details (duration, and whether it's overnight)
  • The journey's total_duration, carbon emissions data, and price
  • An extensions array of flight features, and ticket_also_sold_by
  • A departure_token (used to fetch the return legs of a round trip)

Full field-by-field detail is in the Google Flights API documentation.

Price Insights

Each response also carries a price_insights object, so you can tell whether a fare is a good deal:

  • lowest_price : The cheapest ticket among the options
  • price_level : The affordability tier for that price
  • typical_price_range : A [low, high] array of expected prices for the route
  • price_history : Timestamped price points, ideal for a price-tracking chart

More detail in the price insights documentation. We'll read these fields in the Scrape flight prices section.

Basic Google Flights Data Scraping

You can get structured Google Flights data with a single GET request using SerpApi's Google Flights API.

Prefer to watch? Here's a quick walkthrough of scraping Google Flights with the API:

https://www.youtube.com/embed/zqZSvuj7JMs?feature=oembed

Setting Up a SerpApi Account

SerpApi offers a free plan for newly created accounts. Head to the sign-up page to register an account and complete your first search with our interactive playground.

When you want to do more searches with us, please visit the pricing page.

Once you are familiar with all the results, you can utilize SERP APIs using yourAPI Key.

SerpApi Google Flights API data from playground

SerpApi Google Flights API data from playground

Search by Airport Code

Search a route by IATA airport code (find codes on IATA's site or Google Flights).

Let's find the best flights to Berlin. The data contains: "total_duration", "price", "type", "number_of_flights", and more.

cURL implementation

The simplest way to test the API:

curl --get https://serpapi.com/search \
 -d api_key="SERPAPI_API_KEY" \
 -d engine="google_flights" \
 -d departure_id="AUS" \
 -d arrival_id="BER" \
 -d outbound_date="2026-09-15" \
 -d return_date="2026-09-22"
Enter fullscreen mode Exit fullscreen mode

Python Implementation

First, install the SerpApi client library.

pip install serpapi
Enter fullscreen mode Exit fullscreen mode

Get your API Key fromSerpApicredentials and run a basic search. Store your key as an environment variable (export SERPAPI_KEY=your_key) and read it with os.getenv:

import os
import serpapi

client = serpapi.Client(api_key=os.getenv("SERPAPI_API_KEY"))

params = {
    "engine": "google_flights",
    "departure_id": "AUS",
    "arrival_id": "BER",
    "outbound_date": "2026-09-15",
    "return_date": "2026-09-22",
    "currency": "USD",
    "hl": "en",
}

results = client.search(params)
print(results)
Enter fullscreen mode Exit fullscreen mode

The results object behaves like a regular dictionary, so you can read fields straight off it.

Let's say you only want the price, total duration, type, and number of flights from each of the best options:

for item in results.get("best_flights", []):
    print("Price:", item.get("price"))
    print("Total duration (min):", item.get("total_duration"))
    print("Type:", item.get("type"))
    print("Number of flights:", len(item.get("flights", [])))
    print("-" * 20)
Enter fullscreen mode Exit fullscreen mode

Finally, let's export the data to a CSV file for easier analysis.

import csv

header = ["total_duration", "price", "type", "number_of_flights"]

with open("google_flights.csv", "w", encoding="UTF8", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(header)
    for item in results.get("best_flights", []):
        writer.writerow([
            item.get("total_duration"),
            item.get("price"),
            item.get("type"),
            len(item.get("flights", [])),
        ])

print("Data exported to google_flights.csv")
Enter fullscreen mode Exit fullscreen mode

The result:

Google Flight Result in CSV format

Google Flight Result in CSV format

JavaScript Implementation

Install the serpapi package:

npm install serpapi
Enter fullscreen mode Exit fullscreen mode

Run a basic query:

const { getJson } = require("serpapi");

getJson({
    api_key: "SERPAPI_API_KEY",
    engine: "google_flights",
    departure_id: "AUS",
    arrival_id: "BER",
    outbound_date: "2026-09-15",
    return_date: "2026-09-22",
    currency: "USD",
    hl: "en",
}, (results) => {
    console.log(results["best_flights"]);
});
Enter fullscreen mode Exit fullscreen mode

More on the library: serpapi-javascript on GitHub.

You can call the API with a plain GET request in any language. Ready-made libraries for Ruby, PHP, Java, Go, and more are listed on SerpApi Integrations.

Search by city ID

To include every airport in a city, search by city ID instead of an airport code. City IDs can be retrieved with the Google Maps API:

params.update({"departure_id": "/m/04jpl", "arrival_id": "/m/07dfk"})
results = client.search(params)
Enter fullscreen mode Exit fullscreen mode

Customize the Flight Search

The API exposes the same controls you'd use on Google Flights itself. Add any of these to the params dict from the basic search, then run client.search(params) again.

Round-trip vs. one-way

Set type to 1 for a round trip (default), 2 for one-way, or 3 for multi-city. A round trip needs a return_date:

params.update({
    "type": "1",
    "outbound_date": "2026-09-15",
    "return_date": "2026-09-22",
})
Enter fullscreen mode Exit fullscreen mode

Retrieving the returning flights

A round-trip search returns only the outbound flights first. Each outbound flight carries its own departure_token, you need to pass it back to get that flight's return options:

params.update({
    "type": "1",
    "departure_token": "PASTE_DEPARTURE_TOKEN_FROM_PREVIOUS_RESPONSE",
})
Enter fullscreen mode Exit fullscreen mode

(This is the Google Flights equivalent of pagination. You drill into a flight rather than page through a list.)

Scrape flight prices and price insights

Prices are usually the whole point of a flight price scraper. Every response carries the fare on each option plus the price_insights object described in the data structure.

import os
import serpapi

client = serpapi.Client(api_key=os.getenv("SERPAPI_API_KEY"))

results = client.search({
    "engine": "google_flights",
    "departure_id": "JFK",
    "arrival_id": "LHR",
    "outbound_date": "2026-09-15",
    "return_date": "2026-09-22",
    "currency": "USD",
})

insights = results.get("price_insights", {})
print("Lowest price:", insights.get("lowest_price"))
print("Price level:", insights.get("price_level"))            # e.g. "low", "typical", "high"
print("Typical range:", insights.get("typical_price_range"))  # [low, high]

# The cheapest fares from the results themselves
for item in results.get("best_flights", []):
    print(item.get("price"), "-", item.get("total_duration"), "min")
Enter fullscreen mode Exit fullscreen mode

Because the response is already structured, scraping flight pricing is just reading fields without HTML parsing or broken selectors. To watch a route over time, run the same request on a schedule and store lowest_price and price_history on each run.

Cabin class

travel_class: 1 Economy (default), 2 Premium economy, 3 Business, 4 First.

params.update({"travel_class": "3"})   # Business
Enter fullscreen mode Exit fullscreen mode

Filter by airline

exclude_airlines drops carriers while include_airlines keeps only the ones you name (comma-separated). The two can't be combined:

params.update({"exclude_airlines": "MH,EY"})   # or {"include_airlines": "QF"}
Enter fullscreen mode Exit fullscreen mode

Stops, duration, and other filters

Filter by number of stops with stops: 0 any (default), 1 nonstop only, 2 one stop or fewer, 3 two stops or fewer.

params.update({"stops": "1"})   # nonstop only
Enter fullscreen mode Exit fullscreen mode

Add any of these to narrow results further:

  • max_duration : The total trip-time cap in minutes (e.g. "1400")
  • layover_duration : Layover range in minutes, two-number string (e.g. "250,300")
  • exclude_conns : Exclude a connecting airport by ID (e.g. "AUH")
  • outbound_times / return_times : Departure hour ranges (e.g. "14,18" = 2–6 PM)
  • max_price : Upper price limit for the whole trip (e.g. "600")
  • sort_by : 1 Top flights (default), 2 Price, 3 Departure time, 4 Arrival time, 5 Duration, 6 Emissions

For full list check out the advanced filter parameters in the documentation.

Flexible dates

Google Flights has no native flexible-date search, but a few lines turn the API into a flexible-date flight scraper. Loop over a window and collect the cheapest fare per day:

import os
import serpapi
from datetime import date, timedelta

client = serpapi.Client(api_key=os.getenv("SERPAPI_API_KEY"))

def search_flexible_dates(origin, destination, flexible_days):
    start = date(2026, 9, 15)
    for i in range(flexible_days):
        outbound = start + timedelta(days=i)
        return_date = outbound + timedelta(days=7)   # adjust trip length as needed

        results = client.search({
            "engine": "google_flights",
            "departure_id": origin,
            "arrival_id": destination,
            "outbound_date": outbound.isoformat(),
            "return_date": return_date.isoformat(),
            "currency": "USD",
            "hl": "en",
            "type": "1",
        })
        print(f"\nOutbound: {outbound} | Return: {return_date}")
        for item in results.get("best_flights", []):
            for flight in item["flights"]:
                print(
                    f"{flight['flight_number']} | "
                    f"{flight['departure_airport']['id']} -> {flight['arrival_airport']['id']} | "
                    f"{flight['airline']} | {item['total_duration']} min | "
                    f"{item['price']} {results['search_parameters']['currency']}"
                )

search_flexible_dates("JFK", "LAX", 3)
Enter fullscreen mode Exit fullscreen mode

Groups of passengers

Tailor results to a group with adults, children, infants_in_seat, and infants_on_lap:

params.update({
    "adults": "3",
    "children": "2",
    "infants_in_seat": "1",
    "infants_on_lap": "1",
})
Enter fullscreen mode Exit fullscreen mode

Bonus: Deals and airport autocomplete

Frequently Asked Questions (FAQs)

Is it legal to scrape Google Flights?

Collecting publicly available data is generally permitted, and using an API like SerpApi keeps you off Google's infrastructure. Always review the applicable terms of service for your use case.

How do I scrape flight prices?

Send a Google Flights API request for your route and read the price on each flight plus the price_insights object (lowest_price, price_level, typical_price_range, price_history). See the scrape flight prices section above for a working example.

How do I scrape Google Flights in Python?

Install the serpapi package (pip install serpapi), create a client with your API key, and call client.search() with engine="google_flights" and your route parameters. The results are returned in JSON format, so no HTML scraping is required. The full code is in Basic Google Flights Data Scraping.

How much does it cost?

Register at serpapi.com to start for free with 250 searches per month. Paid plans scale with your usage.

Why scrape Google Flights data?

Live flight prices, routes, and availability power price-comparison tools, fare trackers, travel dashboards, and market analysis for travel businesses without maintaining a fragile scraper.

Wrapping Up

That's it! You can now scrape Google Flights end-to-end: set up the API, understand the response, run a basic search, and customize it by route, dates, prices, class, filters, and passengers. Experiment for free in the Google Flights playground.

Building a broader travel product? Pair this with our other travel APIs:

If you have any questions, feel free to contact our team at contact@serpapi.com.

Top comments (0)