# Deutsche Bahn Scraper - Train Schedules & Prices (`studio-amba/deutsche-bahn-scraper`) Actor

Scrape train connections, schedules, and prices from Deutsche Bahn (bahn.de). Extract ICE, IC, RE, and S-Bahn routes with departure/arrival times, duration, transfers, carriers, and live fares across Germany and Europe.

- **URL**: https://apify.com/studio-amba/deutsche-bahn-scraper.md
- **Developed by:** [Studio Amba](https://apify.com/studio-amba) (community)
- **Categories:** Travel
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Deutsche Bahn Scraper

Scrape **train connections, schedules, and prices** from [Deutsche Bahn](https://www.bahn.de) (bahn.de), Germany's national railway operator with over 50 million monthly visitors. Extract ICE, IC, RE, RB, and S-Bahn routes with departure/arrival times, durations, transfer counts, platform numbers, carrier information, and live ticket fares.

No login or cookies required. The actor handles bahn.de's complex SPA and anti-bot protections automatically using residential proxies and a headless browser.

### How to scrape Deutsche Bahn data

1. Go to [Deutsche Bahn Scraper](https://apify.com/studio-amba/deutsche-bahn-scraper) on the Apify Store.
2. Click **Try for free** to open the actor in Apify Console.
3. Enter your **origin** and **destination** stations (e.g., "Berlin Hbf" to "München Hbf").
4. Optionally set a departure date and time.
5. Click **Start** and wait for the results.
6. Download your data in JSON, CSV, Excel, or connect it directly to your workflow via API.

### Why use this actor?

- **Comprehensive data** — Get full connection details including train types, prices, platforms, transfer counts, and individual journey legs in a single run.
- **No login needed** — Extracts publicly available schedule and pricing data without any Deutsche Bahn account.
- **Handles the SPA** — bahn.de is a complex single-page application. This actor uses Playwright to properly render the page and extract data that simple HTTP scrapers miss.
- **Scheduled runs** — Set up daily or hourly schedules to monitor price changes on your preferred routes.
- **API access** — Integrate train data directly into your applications, dashboards, or business workflows using the Apify API.

### Input

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `origin` | string | `Berlin Hbf` | Departure station name. Partial names are resolved automatically. |
| `destination` | string | `München Hbf` | Arrival station name. Partial names are resolved automatically. |
| `departureDate` | string | Tomorrow | Search date in `YYYY-MM-DD` format. |
| `departureTime` | string | `08:00` | Earliest departure time in `HH:MM` format (24h). |
| `travelClass` | string | `2` | Travel class: `1` (First) or `2` (Second). |
| `maxResults` | integer | `20` | Maximum number of connections to return (1-200). |
| `proxyConfiguration` | object | Residential DE | Proxy settings. Residential proxies with a German exit node are recommended. |

#### Example input

```json
{
    "origin": "Berlin Hbf",
    "destination": "München Hbf",
    "departureDate": "2026-06-15",
    "departureTime": "08:00",
    "travelClass": "2",
    "maxResults": 20,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "DE"
    }
}
````

### Output

The actor produces a dataset with one item per train connection. You can download the dataset in various formats such as JSON, HTML, CSV, or Excel.

#### Example output

```json
{
    "origin": "Berlin Hbf",
    "destination": "München Hbf",
    "departureTime": "2026-06-15T08:15:00+02:00",
    "arrivalTime": "2026-06-15T12:10:00+02:00",
    "duration": "3h 55min",
    "durationMinutes": 235,
    "trainType": "ICE",
    "trainNumber": "ICE 1001",
    "price": 29.90,
    "currency": "EUR",
    "travelClass": "2",
    "transfers": 0,
    "legs": [
        {
            "origin": "Berlin Hbf",
            "destination": "München Hbf",
            "departureTime": "2026-06-15T08:15:00+02:00",
            "arrivalTime": "2026-06-15T12:10:00+02:00",
            "trainType": "ICE",
            "trainNumber": "ICE 1001",
            "carrier": "DB Fernverkehr",
            "departurePlatform": "6",
            "arrivalPlatform": "12"
        }
    ],
    "carrier": "DB Fernverkehr",
    "departurePlatform": "6",
    "arrivalPlatform": "12",
    "url": "https://int.bahn.de/en/buchung/fahrplanauskunft?...",
    "scrapedAt": "2026-06-09T14:30:00.000Z"
}
```

### Data fields

| Field | Type | Description |
|-------|------|-------------|
| `origin` | string | Departure station name |
| `destination` | string | Arrival station name |
| `departureTime` | string | ISO 8601 departure timestamp |
| `arrivalTime` | string | ISO 8601 arrival timestamp |
| `duration` | string | Human-readable duration (e.g., "3h 55min") |
| `durationMinutes` | number | Duration in minutes for easy sorting/filtering |
| `trainType` | string | Primary train category: ICE, IC/EC, RE/RB, S-Bahn, TGV, etc. |
| `trainNumber` | string | Full train identifier (e.g., "ICE 1001") |
| `price` | number | Ticket price in EUR (0 if not available) |
| `currency` | string | Always "EUR" |
| `travelClass` | string | Travel class searched (1 or 2) |
| `transfers` | number | Number of transfers/changes |
| `legs` | array | Individual trip segments with per-leg train details |
| `carrier` | string | Operating railway company (e.g., "DB Fernverkehr") |
| `departurePlatform` | string | Departure platform/track number |
| `arrivalPlatform` | string | Arrival platform/track number |
| `url` | string | Direct link to this connection on bahn.de |
| `scrapedAt` | string | ISO 8601 timestamp of when the data was collected |

### How much does it cost to scrape Deutsche Bahn?

The actor uses Playwright with residential proxies, which consumes approximately **0.2-0.5 compute units per run** for a typical search of 20 connections. That translates to roughly $0.05-$0.12 per run at standard Apify pricing. Running daily monitoring on a single route would cost approximately $1.50-$3.60 per month.

For high-volume usage, increase `maxResults` and use the pagination feature to get more connections per run rather than running multiple separate searches.

### Tips

- **Use German station names** for best results. "München Hbf" works better than "Munich Central".
- **Prices may not always be available** — Deutsche Bahn shows prices dynamically and some connections may return a price of 0. This typically means the fare is not yet released or sold out.
- **Schedule runs** during off-peak hours for the most reliable results.
- **Residential proxies** with a German exit node (`DE`) are strongly recommended. bahn.de has Akamai protection that blocks datacenter IPs.
- **Search ahead** — Deutsche Bahn releases tickets 6 months in advance. Earlier searches tend to show lower "Sparpreis" fares.

### FAQ

#### Is it legal to scrape Deutsche Bahn?

This actor extracts publicly available train schedule and pricing data from bahn.de. The data is accessible to any visitor without login. Always review Deutsche Bahn's Terms of Service and ensure your use case complies with applicable laws and regulations.

#### Why are some prices showing as 0?

Deutsche Bahn loads prices dynamically and some fare classes may not be available for all connections. A price of 0 means the fare was not displayed on the search results page. Try searching for a closer departure date when prices are more likely to be published.

#### The actor returned no results — what should I do?

- Make sure your station names are valid German station names (e.g., "Frankfurt (Main) Hbf" not "Frankfurt Airport").
- Check that your departure date is in the future.
- Ensure you are using residential proxies with a German exit node.
- Try a popular route like "Berlin Hbf" to "München Hbf" to verify the actor is working.

#### Can I scrape international routes?

Yes, Deutsche Bahn covers international connections to Austria, Switzerland, France, Netherlands, Belgium, Czech Republic, Poland, Denmark, and more. Enter the destination as it appears on bahn.de (e.g., "Wien Hbf", "Zürich HB", "Paris Est").

### Support

If you encounter any issues or have feature requests, please open an issue in the [Issues tab](https://console.apify.com/actors/studio-amba~deutsche-bahn-scraper/issues). For custom solutions or bulk data needs, reach out via the Apify platform.

# Actor input Schema

## `origin` (type: `string`):

Departure station name (e.g. 'Berlin Hbf', 'Hamburg', 'Frankfurt am Main'). The actor resolves partial names automatically.

## `destination` (type: `string`):

Arrival station name (e.g. 'München Hbf', 'Köln', 'Dresden'). The actor resolves partial names automatically.

## `departureDate` (type: `string`):

Date to search for connections in YYYY-MM-DD format. Defaults to tomorrow if not set.

## `departureTime` (type: `string`):

Earliest departure time in HH:MM format (24h). Defaults to 08:00.

## `travelClass` (type: `string`):

Ticket class to search for.

## `maxResults` (type: `integer`):

Maximum number of train connections to return.

## `proxyConfiguration` (type: `object`):

Proxy settings. The actor uses the public HAFAS API, so datacenter proxies usually work fine. Use residential proxies only if you experience rate limiting.

## Actor input object example

```json
{
  "origin": "Berlin Hbf",
  "destination": "München Hbf",
  "departureTime": "08:00",
  "travelClass": "2",
  "maxResults": 20,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "DE"
  }
}
```

# 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 = {
    "origin": "Berlin Hbf",
    "destination": "München Hbf",
    "departureDate": "",
    "departureTime": "08:00",
    "maxResults": 20,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "DE"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("studio-amba/deutsche-bahn-scraper").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 = {
    "origin": "Berlin Hbf",
    "destination": "München Hbf",
    "departureDate": "",
    "departureTime": "08:00",
    "maxResults": 20,
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "DE",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("studio-amba/deutsche-bahn-scraper").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "origin": "Berlin Hbf",
  "destination": "München Hbf",
  "departureDate": "",
  "departureTime": "08:00",
  "maxResults": 20,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "DE"
  }
}' |
apify call studio-amba/deutsche-bahn-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=studio-amba/deutsche-bahn-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Deutsche Bahn Scraper - Train Schedules & Prices",
        "description": "Scrape train connections, schedules, and prices from Deutsche Bahn (bahn.de). Extract ICE, IC, RE, and S-Bahn routes with departure/arrival times, duration, transfers, carriers, and live fares across Germany and Europe.",
        "version": "0.1",
        "x-build-id": "HqzakRvJlnq8SfGYZ"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/studio-amba~deutsche-bahn-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-studio-amba-deutsche-bahn-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/studio-amba~deutsche-bahn-scraper/runs": {
            "post": {
                "operationId": "runs-sync-studio-amba-deutsche-bahn-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/studio-amba~deutsche-bahn-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-studio-amba-deutsche-bahn-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "origin": {
                        "title": "Origin Station",
                        "type": "string",
                        "description": "Departure station name (e.g. 'Berlin Hbf', 'Hamburg', 'Frankfurt am Main'). The actor resolves partial names automatically.",
                        "default": "Berlin Hbf"
                    },
                    "destination": {
                        "title": "Destination Station",
                        "type": "string",
                        "description": "Arrival station name (e.g. 'München Hbf', 'Köln', 'Dresden'). The actor resolves partial names automatically.",
                        "default": "München Hbf"
                    },
                    "departureDate": {
                        "title": "Departure Date",
                        "type": "string",
                        "description": "Date to search for connections in YYYY-MM-DD format. Defaults to tomorrow if not set."
                    },
                    "departureTime": {
                        "title": "Departure Time",
                        "type": "string",
                        "description": "Earliest departure time in HH:MM format (24h). Defaults to 08:00.",
                        "default": "08:00"
                    },
                    "travelClass": {
                        "title": "Travel Class",
                        "enum": [
                            "1",
                            "2"
                        ],
                        "type": "string",
                        "description": "Ticket class to search for.",
                        "default": "2"
                    },
                    "maxResults": {
                        "title": "Max Results",
                        "minimum": 1,
                        "maximum": 200,
                        "type": "integer",
                        "description": "Maximum number of train connections to return.",
                        "default": 20
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy settings. The actor uses the public HAFAS API, so datacenter proxies usually work fine. Use residential proxies only if you experience rate limiting."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
