# FlixBus Fare Scraper (Bus Ticket Prices by Route) (`steadfetch/flixbus-fare-quotes-extractor`) Actor

Extract published Flixbus bus fare quotes by route URL: the 'from' price, currency and route name. Server-side HTML only, no browser, no login, schema-validated results, pay per event.

- **URL**: https://apify.com/steadfetch/flixbus-fare-quotes-extractor.md
- **Developed by:** [Steadfetch](https://apify.com/steadfetch) (community)
- **Categories:** Travel
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 route fare delivereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Flixbus Bus Fare Quotes by Route

Extract the **published "from" fare** of public FlixBus route pages
(`https://www.flixbus.com/bus/<city>`): the route name, the amount, the currency
exactly as FlixBus publishes it, and the source URL. No login, no browser, no
fare estimation.

### What it does

- Reads one public FlixBus route page per URL with a plain HTTP request (no
  browser, no proxy, no IP rotation).
- Returns one dataset item per route that publishes a "from" fare: `routeUrl`,
  `routeName`, `fareFrom` (`amount` + ISO `currency`), `date`, `sourceUrl` and
  `scrapedAt`.
- Parses the server-rendered "cheapest trip" card (`From $13.98`, `Ab 13,98 EUR`,
  `A partir de 8,48 EUR`...) and the route name from the page's
  `BreadcrumbList` JSON-LD.
- Never invents a fare: a route without a published amount, a page that does
  not exist and a route already delivered by a previous run are **not pushed**,
  so they are never charged.
- Deduplicates by canonical `routeUrl` across runs: the second run on the same
  input returns 0 routes. Clear the `seen-routes` key in the
  `flixbus-fare-quotes-state` key-value store to force a fresh backfill.
- Rejects `/track/`, `/flux/` and `format` query parameters on every URL and on
  every redirect; stops on 401/403/429/451 instead of evading a block.
- Emits no personal data: the schema is closed (`additionalProperties: false`)
  and only route-level public fields are read.

Data source: **FlixBus public route pages** (`https://www.flixbus.com/bus/`).
Every item carries `sourceUrl` for attribution.

### Example output

```json
{
  "url": "https://www.flixbus.com/bus/hanover-airport",
  "title": "Hanover Airport",
  "routeUrl": "https://www.flixbus.com/bus/hanover-airport",
  "routeName": "Hanover Airport",
  "fareFrom": { "amount": 13.98, "currency": "USD" },
  "date": null,
  "sourceUrl": "https://www.flixbus.com/bus/hanover-airport",
  "scrapedAt": "2026-10-21T16:50:00.000Z"
}
```

### Input

| Field | Type | Default | Meaning |
|---|---|---|---|
| `routeUrls` | array of URIs, 1-500 | `https://www.flixbus.com/bus/hanover-airport` | Public FlixBus `/bus/<city>` pages to read. HTTPS only; `/track/`, `/flux/` and `format` query parameters are rejected. |
| `locale` | `en`, `de`, `fr` or `es` | `en` | `Accept-Language` hint. The currency reported is always the one the page publishes. |

### Pricing

Pay per event:

- `apify-actor-start`: **0.00005 USD** per run (Apify-recommended default).
- `apify-default-dataset-item`: **0.002 USD** per route delivered, i.e.
  **2.00 USD per 1,000 routes**.

There is no custom per-item event: the synthetic dataset event already charges
per result, so a route is never billed twice. Routes without a published fare,
404 pages and routes already delivered by a previous run are not pushed and are
not charged.

Cost per 1,000 routes: measured locally at 256 MB on a real 87 KB page, a warm
fetch + extraction takes **11.4-18.3 ms** (cold request 209.7 ms); extraction
alone is **16.9 ms** per page. With the built-in 250 ms politeness delay
between requests, a route costs about 0.27 s of compute, i.e. **< 0.01 USD per
1,000 routes** at 0.20 USD/CU (upper bound 0.014 USD/1k if every request took
1 s). Margin over the 2.00 USD/1k price is above 99 %; Apify retains its usual
platform commission.

### FAQ

**Does it need a login, an API key or a proxy?**
No. The fares are on public route pages. The Actor sends an honest
`User-Agent` and stops on 401/403/429/451 instead of trying to evade a block.

**Why is `date` null?**
FlixBus route pages publish a route-level "from" fare, not a date-specific
quote. A query string with a date returns the same page, so v1 does not
pretend to know a travel date; it reports `null` rather than inventing one.

**Why does the second run return zero routes?**
Deduplication is by canonical `routeUrl` and persists in a named key-value
store, so a route is never delivered or charged twice. Clear the `seen-routes`
key in the `flixbus-fare-quotes-state` store to backfill again.

**What happens to a route without a published fare?**
It is skipped: no dataset item, no charge, and the run log says so. The schema
allows `fareFrom: null` for API stability, but the Actor never pushes an item
without a published amount.

**Are prices converted to another currency?**
No. `fareFrom.currency` is the ISO code of the symbol the page publishes
(USD, EUR or GBP). Amounts are never converted or estimated.

**Where does the data come from?**
Public FlixBus route pages. Every item carries `sourceUrl`, and the Store
listing cites FlixBus as the data source.

### Maintenance

Tested daily: a scheduled run validates the public page and the dataset schema
every day. Failures become issues in the Steadfetch Actors repository. `npm
test`, `npm run publish:check` and `apify-cli validate-schema` run in CI on
every push.

# Actor input Schema

## `routeUrls` (type: `array`):

Public route pages on www.flixbus.com/bus/<city>. HTTPS only; /track/, /flux/ and format query parameters are rejected.

## `locale` (type: `string`):

Accept-Language hint sent to FlixBus (en, de, fr or es). The currency reported is always the one the page publishes; the Actor never converts amounts.

## Actor input object example

```json
{
  "routeUrls": [
    "https://www.flixbus.com/bus/hanover-airport"
  ],
  "locale": "en"
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items validated against the item schema in dataset_schema.json (fields).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "routeUrls": [
        "https://www.flixbus.com/bus/hanover-airport"
    ],
    "locale": "en"
};

// Run the Actor and wait for it to finish
const run = await client.actor("steadfetch/flixbus-fare-quotes-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "routeUrls": ["https://www.flixbus.com/bus/hanover-airport"],
    "locale": "en",
}

# Run the Actor and wait for it to finish
run = client.actor("steadfetch/flixbus-fare-quotes-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "routeUrls": [
    "https://www.flixbus.com/bus/hanover-airport"
  ],
  "locale": "en"
}' |
apify call steadfetch/flixbus-fare-quotes-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,steadfetch/flixbus-fare-quotes-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Wxn2kqNGXnoOJwGo2/builds/O4xdFODt8KMggFffi/openapi.json
