Skip to content

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Google Flights Scraper Examples (Python)

HasData, the Flights API these examples call

Every example request from our Google Flights scraping tutorial. The runner counts dates from today instead of hardcoding them, so the trip shapes stay valid on any day you run them.

Table of Contents

Requirements

Python 3.10 or newer and requests.

pip install requests

The runner reads the API key from the HASDATA_API_KEY environment variable, free after sign-up.

How It Works

run_examples.py keeps the 19 parameter sets in its EXAMPLES list, shifts each outbound date to today plus 45 days while keeping the original trip length, and sends the requests one at a time through the HasData Google Flights API with a 429 retry. The full response each request got back is saved into bodies/. The two token flows run chained, one call supplies the departureToken or bookingToken for the next.

Project Structure

The runner is the only code, the rest is what it saved.

google-flights-scraper/
├── run_examples.py     # 19 parameter sets, relative dates, chained tokens
├── bodies/             # the full response each request got back
└── results/            # run log, probes, and one full sample response

Each body file's name says what its request asked for, from basic_round_trip_LHR-JFK to bags_co2_no-ryanair_LAX-HND.

The Requests

The parameter sets cover one-way and round trips, cabin classes with mixed passenger sets, nonstop and layover filters, airline includes and excludes, bag and CO2 constraints, and the chained token flows for itinerary details and booking options. They double as a reference for the API's parameter names, and bodies/ shows what each one returned, so the response shapes are readable without spending a request.

Results

results/example_runs.json records the verification run, 18 of 19 requests returned 200 with itineraries. The one 422 is deliberate, it keeps the published mistake of a returnDate earlier than the outboundDate so the error body stays documented. results/sample_response.json is one full response with best and other itineraries, prices, layovers and carbon emissions.

Disclaimer

The examples fetch flight listings through an API built for that purpose. Whether and how such collection fits your use depends on jurisdiction and terms, and nothing in this repository is legal advice. Is Web Scraping Legal? covers how we think about the question.

More Resources

Releases

Packages

Contributors

Languages