google-flights-scraper-api
v0.0.1
Published
Node.js client for scraping Google Flights using the ScrapingBee web scraping API.
Downloads
116
Maintainers
Readme
google-flights-scraper-api
A Node.js client for scraping Google Flights through the ScrapingBee web scraping API. This google flights scraper api hands off proxy rotation, headless rendering, and anti-bot handling, and gives you back the rendered page or structured JSON from one Promise-based call.
npm install google-flights-scraper-apiYou'll need a ScrapingBee API key. The free tier gives you 1,000 credits with no card required: scrapingbee.com.
Why use a Google Flights API?
Google has no public google flights api, so the only programmatic route is to scrape the page. That is harder than it looks. Google Flights renders its fares with JavaScript after the initial response, so a plain HTTP fetch returns an empty shell with no prices in it. On top of that, Google rate-limits datacenter IPs and serves consent and challenge pages to traffic that looks automated. And the markup uses obfuscated class names that rotate often, so any selector you hardcode has a short shelf life.
A managed google flights scraper collapses that stack into one HTTP call. ScrapingBee runs the proxies, the headless browser pool, and the rendering, and returns clean output:
https://app.scrapingbee.com/api/v1/This package is a thin Node.js wrapper around that endpoint with camelCase options and a Promise-based interface.
Quick start
const { GoogleFlightsScraper } = require('google-flights-scraper-api');
const scraper = new GoogleFlightsScraper({ apiKey: 'YOUR-API-KEY' });
scraper.search({ query: 'Flights to London from New York' }).then(function (html) {
console.log(html);
});API reference
new GoogleFlightsScraper({ apiKey, timeout })
| Option | Type | Default | Description |
| -------- | ------ | -------- | ------------------------------- |
| apiKey | string | required | Your ScrapingBee API key |
| timeout| number | 60000 | Request timeout in milliseconds |
.search(options)
Every option maps to a documented ScrapingBee HTML API parameter. See the ScrapingBee documentation for the canonical spec.
| Option | API parameter | Type | Default | Description |
| ------------------- | ---------------------- | ------- | ------- | ----------- |
| query | url (?q=) | string | — | Natural-language flight search, appended to the Google Flights URL |
| url | url | string | — | A full Google Flights URL, used instead of query |
| renderJs | render_js | boolean | true | Execute page JavaScript with a headless browser |
| premiumProxy | premium_proxy | boolean | true | Route through residential proxies |
| stealthProxy | stealth_proxy | boolean | false | Stealth tier for the hardest anti-bot blocks |
| countryCode | country_code | string | — | ISO country code; requires premiumProxy |
| aiExtractRules | ai_extract_rules | object | — | Natural-language extraction; returns JSON; adds 5 credits |
| extractRules | extract_rules | object | — | CSS or XPath extraction rules |
| jsScenario | js_scenario | object | — | Script waits, scrolls, and clicks before capture |
| wait | wait | number | — | Fixed wait in milliseconds |
| screenshotFullPage| screenshot_full_page | boolean | false | Return a full-page screenshot as binary |
| jsonResponse | json_response | boolean | false | Wrap the response in a JSON envelope |
Documented constraints:
country_codehas no effect unlesspremium_proxyis enabled.- A
js_scenarioruns for up to 40 seconds total.
You pass either query or url. The client sends the Google CONSENT cookie by default so the consent page is skipped; set skipConsent: false to turn that off.
Response shape
The return value depends on the options you send:
| Call | Returns |
| ---- | ------- |
| Default | The rendered Google Flights HTML as a string |
| With aiExtractRules or extractRules | Parsed JSON matching the schema you defined |
| With jsonResponse: true | A JSON envelope with the page and scenario reports |
| With screenshotFullPage: true | Raw PNG bytes |
Structured extraction example
const { GoogleFlightsScraper } = require('google-flights-scraper-api');
const scraper = new GoogleFlightsScraper({ apiKey: 'YOUR-API-KEY' });
scraper.search({
query: 'Flights to Tokyo from San Francisco',
aiExtractRules: {
flights: {
description: 'every flight result on the page',
type: 'list',
output: {
airline: 'name of the airline',
price: 'ticket price in dollars',
departure_time: 'departure time',
arrival_time: 'arrival time',
duration: 'total trip duration',
stops: 'number of stops',
},
},
},
}).then(function (data) {
console.log(data.flights);
});Use cases
Common scenarios for a Google Flights scraper in a Node.js stack:
- Fare monitoring — schedule
search()per route and alert whenpricedrops below a threshold. - Competitive pricing — compare your published fares against the Google Flights aggregate with
aiExtractRules. - Route research — pull airlines, durations, and stop counts across markets for analysis.
- Travel dashboards — feed structured fare JSON into a customer-facing product or internal tool.
- Slow-loading pages — combine
jsScenariowaits withrenderJswhen results stream in late.
Each scenario is the same .search() call with a different option combination, every option mapped to a documented ScrapingBee parameter above.
Pricing
ScrapingBee bills per successful call. A request that fails with HTTP 500 is not charged. Scraping a Google URL through the HTML API is a flat rate, and toggling JS does not change it:
- Classic or Premium proxy — 20 credits per call
- Stealth proxy — 75 credits per call
aiExtractRules— adds 5 credits
Current rate card and plan tiers: scrapingbee.com/pricing.
FAQ
Is there an official Google Flights API?
No. Google does not publish a public google flights api for fares, so rendering and scraping the public page is the practical option. This package wraps that approach through ScrapingBee.
Why does a plain fetch return no flight prices?
Google Flights injects fares with JavaScript after the page loads, so the raw HTML has none of the data. You need a headless browser to execute the page, which is what renderJs does.
How do I get JSON instead of HTML?
Pass aiExtractRules for natural-language extraction or extractRules for CSS and XPath rules. Both return parsed JSON.
Can I target a specific market or currency?
Set countryCode together with premiumProxy. The country code is ignored without a premium proxy.
How do I handle the Google consent page?
The client sends the Google CONSENT cookie by default. Disable it with skipConsent: false if you want to handle consent yourself.
Is scraping Google Flights allowed?
Public flight data is generally collectible for research and monitoring, but Google's terms and local regulations apply. Scrape public pages only.
Documentation
License
MIT. See LICENSE.
Disclaimer
This is an unofficial Node.js wrapper around the ScrapingBee web scraping API. Not affiliated with ScrapingBee or Google. Compliance with Google's terms of service and applicable data-protection law is the responsibility of the operator.
