惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
爱范儿
爱范儿
Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
B
Blog RSS Feed
博客园 - 聂微东
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Scott Helme
Scott Helme
AI
AI
S
Security Affairs
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
T
Troy Hunt's Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
AWS News Blog
AWS News Blog
T
Threatpost
Cyberwarzone
Cyberwarzone
www.infosecurity-magazine.com
www.infosecurity-magazine.com
U
Unit 42
V
Vulnerabilities – Threatpost
J
Java Code Geeks
博客园 - Franky
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
NISL@THU
NISL@THU
D
Docker
小众软件
小众软件
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
Forbes - Security
Forbes - Security
量子位
PCI Perspectives
PCI Perspectives
美团技术团队
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
腾讯CDC
P
Proofpoint News Feed
S
Security @ Cisco Blogs
G
Google Developers Blog
C
Cisco Blogs

SerpApi

The State of the SERP in the Age of AI How to find the Google Knowledge Graph ID (kgmid) for anything What is an API? Part 2: Feeding the Machine (JSON) Building an Accessibility Search Experience with Google Flights, Hotels, and Maps APIs SerpApi Weekly Changelog: July 06-12, 2026 Monitoring FIFA World Cup scores with a simple API How to scrape Google sports results Build Smarter Pydantic AI Agents with Real-Time Search A complete guide to web scraping with Ruby (2026) SerpApi Weekly Changelog: June 29- July 05, 2026 Make no mistakes: agent usability testing Semantic Image Search with Elasticsearch What is an API? Part 1: The Secret Life of a Web Browser MCP Apps with FastMCP: Turning Tool Output Into Interactive UI How to Scrape Naver AI Briefings with SerpApi Connect Sakana AI (Fugu) with Web Search API SerpApi Weekly Changelog: June 22-28, 2026 Trending Travel Destinations using Python & SerpApi How to scrape Bing reverse image search results Measuring Brand Presence Across AI Answer Engines SerpApi Weekly Changelog: June 15-21, 2026 How I Built a Star Wars Grogu Product Research Agent with Codex, Lark, and SerpApi How to scrape Bing web search results Categorizing hotels using Google Hotels images How to scrape Bing Images search results How to scrape Bing Copilot answers Build A No Code AI-Powered Local Lead Outreach System SerpApi Weekly Changelog: June 08-14, 2026 How to Do SEO Research with Claude Desktop and SerpApi MCP Track and Compare Product Prices Across Stores and Locations (SerpApi & Python) How to Extract Full Opinion Text from Google Scholar Case Law with SerpApi How to scrape Bing Maps search results SerpApi Weekly Changelog: June 01-07, 2026 Amazon ASIN Lookup API: Find and Fetch Product Details The State of MCP: Everything That Changed in H1 2026 How to scrape Bing News search results How to Connect Your Local LLM with Web Search Data SerpApi on Postman: One Unified Collection for Faster API Exploration SerpApi Weekly Changelog: May 25-31, 2026 Building an AI Agent in Python How to scrape Google Case Law API for Legal Research, Analytics, AI, and more SerpApi Achieves SOC 2 Type 2 and ISO 27001 Certification How to find your next product idea with Google Trends and SerpApi Scrape Competitors' Google Ads Data (Tutorial 2026) Using SerpApi and DeepSeek to Break Down Dan Koe’s Content Strategy SerpApi Weekly Changelog: May 18-24, 2026 How to scrape Bing Videos search results How to Scrape Instagram Profile Data with SerpApi How to scrape Bing Shopping search results How to Scrape Google Hotels Reviews SerpApi Weekly Changelog: May 11-17, 2026 5 Things You Can Build with Claude Code and Live Search Data Real Estate Data API for PropTech Developers How to Scrape Apple Maps with SerpApi How to scrape Google Trends
How to Scrape Google Flights Deals with a simple API
Hilman Ramadhan · 2026-07-11 · via SerpApi

Google Flights Deals helps travelers discover discounted flights without a specific destination. Instead of searching one route at a time, you can start with a departure airport or city and explore discounted destinations.

This data can be useful for building flight-deal trackers, travel discovery tools, price-comparison dashboards, or destination-recommendation apps. In this tutorial, we'll use SerpApi's Google Flights Deals API to retrieve flight deals as structured JSON with cURL, Python, and JavaScript.

Scrape Google Flights Deals website

How to use the Google Flights Deals API

A basic request uses these parameters:

ParameterRequirementDescription
engineRequiredSet to google_flights_deals
api_keyRequiredYour private SerpApi API key
departure_idOptionalDeparture airport code or location ID
currencyOptionalCurrency used for returned prices

An airport ID is normally an uppercase three-letter IATA code such as:

  • CDG for Paris Charles de Gaulle Airport
  • AUS for Austin-Bergstrom International Airport
  • MAD for Adolfo Suárez Madrid-Barajas Airport

You can also provide a Google location ID beginning with /m/ or /g/. Multiple departure locations can be separated with commas.

Get your API key

Create a SerpApi account and retrieve your private key from the API key page.

Replace the following placeholder in each example:

YOUR_SERPAPI_API_KEY

Never expose your API key in public source code or commit it to a public repository.

The complete parameter reference is available in the official Google Flights Deals API documentation.

cURL implementation

Let's retrieve flight deals departing from Paris Charles de Gaulle Airport:

curl --get https://serpapi.com/search \
 -d engine="google_flights_deals" \
 -d departure_id="CDG" \
 -d currency="USD" \
 -d api_key="YOUR_SERPAPI_API_KEY"

The parameters in this request are:

  • engine=google_flights_deals selects the Google Flights Deals engine.
  • departure_id=CDG searches for deals departing from Paris Charles de Gaulle Airport.
  • currency=USD returns prices in US dollars.

The API returns JSON by default.

Python implementation

Create a new Python file:

main.py

Install the requests package:

pip install requests

Add the following code:

import requests


SERPAPI_API_KEY = "YOUR_SERPAPI_API_KEY"

params = {
    "engine": "google_flights_deals",
    "departure_id": "CDG",
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

response = requests.get(
    "https://serpapi.com/search",
    params=params,
    timeout=30,
)
response.raise_for_status()

data = response.json()

if "error" in data:
    raise RuntimeError(data["error"])

departure = data.get("departure_informations", {})

departure_name = (
    departure.get("airport_name")
    or departure.get("city")
    or "Unknown departure"
)

print(f"Flight deals from: {departure_name}")
print()

for deal in data.get("deals", []):
    duration = deal.get("flight_duration")

    if duration is not None:
        hours, minutes = divmod(duration, 60)
        formatted_duration = f"{hours}h {minutes}m"
    else:
        formatted_duration = "Not available"

    print("Destination:", deal.get("name", "Unknown"))
    print("Country:", deal.get("country", "Unknown"))
    print("Price:", deal.get("price", "Not available"))
    print(
        "Average price:",
        deal.get("average_price", "Not available"),
    )
    print(
        "Discount:",
        deal.get("discount_percentage", "Not available"),
    )
    print("Outbound date:", deal.get("outbound_date", "Not available"))
    print("Return date:", deal.get("return_date", "One-way flight"))
    print(
        "Route:",
        f"{deal.get('departure_airport_code', '?')} → "
        f"{deal.get('arrival_airport_code', '?')}",
    )
    print("Duration:", formatted_duration)
    print("Stops:", deal.get("stops", "Not available"))
    print("Airline:", deal.get("airline", "Not available"))
    print("Google Flights:", deal.get("flight_link", "Not available"))
    print("-" * 80)

The code prints selected fields from every item in the deals array. It also converts the documented flight_duration value from minutes into hours and minutes.

Here is the result

Flights Deals API scraper

Fields are accessed with .get() because some values are not guaranteed to appear in every deal.

Export the flight deals to CSV

You can also save the results to a CSV file for further analysis:

import csv


rows = []

for deal in data.get("deals", []):
    rows.append({
        "destination": deal.get("name", ""),
        "country": deal.get("country", ""),
        "destination_id": deal.get("destination_id", ""),
        "price": deal.get("price", ""),
        "average_price": deal.get("average_price", ""),
        "discount_percentage": deal.get(
            "discount_percentage",
            "",
        ),
        "outbound_date": deal.get("outbound_date", ""),
        "return_date": deal.get("return_date", ""),
        "departure_airport": deal.get(
            "departure_airport_code",
            "",
        ),
        "arrival_airport": deal.get(
            "arrival_airport_code",
            "",
        ),
        "flight_duration_minutes": deal.get(
            "flight_duration",
            "",
        ),
        "stops": deal.get("stops", ""),
        "airline": deal.get("airline", ""),
        "airline_code": deal.get("airline_code", ""),
        "google_flights_link": deal.get("flight_link", ""),
        "serpapi_flight_link": deal.get(
            "serpapi_flight_link",
            "",
        ),
    })

fieldnames = [
    "destination",
    "country",
    "destination_id",
    "price",
    "average_price",
    "discount_percentage",
    "outbound_date",
    "return_date",
    "departure_airport",
    "arrival_airport",
    "flight_duration_minutes",
    "stops",
    "airline",
    "airline_code",
    "google_flights_link",
    "serpapi_flight_link",
]

with open(
    "google_flights_deals.csv",
    "w",
    newline="",
    encoding="utf-8",
) as csv_file:
    writer = csv.DictWriter(
        csv_file,
        fieldnames=fieldnames,
    )
    writer.writeheader()
    writer.writerows(rows)

print(
    f"Saved {len(rows)} deals to "
    "google_flights_deals.csv"
)

This creates a file named google_flights_deals.csv with one row for each deal.

Exported result in CSV file

JavaScript implementation

SerpApi provides an official JavaScript package.

Install it with npm:

npm install serpapi

Create an index.js file:

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

const SERPAPI_API_KEY = "YOUR_API_KEY";

getJson(
  {
    engine: "google_flights_deals",
    departure_id: "CGK",
    currency: "USD",
    api_key: SERPAPI_API_KEY,
  },
  (json) => {
    if (json.error) {
      console.error(json.error);
      return;
    }

    const departure = json.departure_informations || {};
    const deals = json.deals || [];

    console.log(
      `Flight deals from: ${
        departure.airport_name ||
        departure.city ||
        "Unknown departure"
      }\n`
    );

    deals.forEach((deal) => {
      console.log({
        destination: deal.name || "Unknown",
        country: deal.country || "Unknown",
        price: deal.price ?? "Not available",
        averagePrice:
          deal.average_price ?? "Not available",
        discountPercentage:
          deal.discount_percentage ?? "Not available",
        outboundDate:
          deal.outbound_date || "Not available",
        returnDate:
          deal.return_date || "One-way flight",
        route:
          `${deal.departure_airport_code || "?"} → ` +
          `${deal.arrival_airport_code || "?"}`,
        duration: deal.flight_duration ?? "Not available",
        stops: deal.stops ?? "Not available",
        airline: deal.airline || "Not available",
        flightLink: deal.flight_link || "Not available",
      });
    });
  }
);

Run the script:

node index.js

The official SerpApi JavaScript package exposes the getJson function and supports both callbacks and promises.

Customize Google Flights Deals results

The API provides several ways to customize the returned deals. Here are three useful examples.

Search using exact or flexible dates

For an exact round trip, provide one outbound_date and one return_date in YYYY-MM-DD format:

params = {
    "engine": "google_flights_deals",
    "departure_id": "FCO",
    "outbound_date": "2026-08-10",
    "return_date": "2026-08-17",
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

For flexible dates, use two comma-separated dates as the departure window:

params = {
    "engine": "google_flights_deals",
    "departure_id": "BCN",
    "outbound_date": "2026-09-01,2026-09-30",
    "travel_duration": 3,
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

Possible travel_duration values are:

ValueDuration
1One week
2Weekend
3Two weeks

You can alternatively use trip_length for a custom duration:

params["trip_length"] = "5,10"

This requests trips lasting between 5 and 10 days.

travel_duration, trip_length, and return_date cannot be used together. For a round trip with one exact outbound date, one exact return date is required.

Filter by stops and maximum price

Use stops to control how many connections are allowed:

ValueMeaning
0Any number of stops
1Nonstop only
2One stop or fewer
3Two stops or fewer

You can combine it with max_price:

params = {
    "engine": "google_flights_deals",
    "departure_id": "CDG",
    "stops": 1,
    "max_price": 500,
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

This searches for nonstop deals costing no more than 500 in the selected currency.

Include or exclude airlines

Use include_airlines to return deals from selected airlines:

params = {
    "engine": "google_flights_deals",
    "departure_id": "/m/0947l",
    "include_airlines": "W4,FR",
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

The example includes:

  • W4 — Wizz Air
  • FR — Ryanair

Multiple airline codes are separated with commas.

You can use exclude_airlines instead when you want to remove specific airlines from the results:

params["exclude_airlines"] = "UA"

The include_airlines and exclude_airlines parameters cannot be used together.

The API also accepts the following alliance values:

  • STAR_ALLIANCE
  • SKYTEAM
  • ONEWORLD

Searching for one-way flight deals

Round trip is the default flight type. Set type to 2 to search for one-way deals:

params = {
    "engine": "google_flights_deals",
    "departure_id": "MAD",
    "type": 2,
    "currency": "USD",
    "api_key": SERPAPI_API_KEY,
}

The supported values are:

ValueFlight type
1Round trip
2One way

For a one-way search with a specific date, provide only outbound_date:

params["outbound_date"] = "2026-09-15"

Do not use return_date, travel_duration, or trip_length with one-way flights. One-way deal results do not contain an return_date.

What data can be retrieved from the Google Flights Deals API?

The API returns information about the departure location and a list of available flight deals.

The departure_informations object can include:

  • Departure airport name and IATA code
  • Departure city and city ID
  • Departure country
  • Airport latitude and longitude

The deals array can include:

  • Destination name and country
  • Destination Google Knowledge Graph ID
  • Deal price
  • Average price for the route
  • Discount percentage
  • Outbound and return dates
  • Departure and arrival airport codes
  • Flight duration in minutes
  • Number of stops
  • Airline name and code
  • Destination description and highlights
  • Destination thumbnail
  • Direct Google Flights link
  • SerpApi link for retrieving detailed flight information

Some fields, including average_price, discount_percentage, airline, and description, are not always present. The return_date field is also omitted for one-way flights.

Here is a simplified example of a deal:

{
  "destination_id": "/m/0k02q",
  "name": "São Vicente",
  "country": "Cape Verde",
  "price": 468,
  "average_price": 2023,
  "discount_percentage": 77,
  "outbound_date": "2026-09-21",
  "return_date": "2026-09-27",
  "departure_airport_code": "CDG",
  "arrival_airport_code": "VXE",
  "flight_duration": 350,
  "stops": 0,
  "airline": "Cabo Verde Airlines",
  "airline_code": "VR",
  "flight_link": "https://www.google.com/travel/flights?..."
}

The main results are available inside the deals array.

Scraping Google Flights

Here is a video tutorial if you prefer to watch

Conclusion

The SerpApi Google Flights Deals API makes it possible to retrieve Google Flights deal discovery results as structured JSON.

With one request, you can collect destinations, deal prices, average prices, discount percentages, travel dates, airport codes, airlines, flight durations, stops, and links to Google Flights.

You can also customize the search using exact dates, flexible date ranges, trip durations, maximum prices, stop limits, travel classes, and airline filters.

For the complete and current parameter list, review the official Google Flights Deals API documentation.