# České Dráhy Connections Scraper (`jindrich.bar/ceske-drahy-connections`) Actor

Scrape train connections from České Dráhy (Czech state railways) with departure dates, prices, train types, and more.

- **URL**: https://apify.com/jindrich.bar/ceske-drahy-connections.md
- **Developed by:** [Jindřich Bär](https://apify.com/jindrich.bar) (community)
- **Categories:** Developer tools, Travel, E-commerce
- **Stats:** 3 total users, 0 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $0.50 / 1,000 search results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## 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

## České dráhy connection scraper

Search train connections on [cd.cz](https://www.cd.cz/) and get back a structured dataset of routes,
times, train legs, and prices.

### What it does

Given a departure station, a destination, and an optional date/time, the actor finds the next train
connections offered by České dráhy and stores them in the dataset. For each connection you get:

- Departure and arrival as ISO timestamps
- Total travel time in minutes
- Number of transfers
- Per-train breakdown: name, carrier, end station, departure / arrival, distance in kilometres, expected occupancy
- Price in CZK (when ticketing is available)

The actor automatically paginates over the cd.cz timetable and skips gaps in service so you reliably
get the requested number of connections — even for routes where direct service runs only on selected
days.

### Inputs

| Field | Required | Default | Description |
| --- | --- | --- | --- |
| `from` | yes | — | Departure station name (Czech diacritics supported) |
| `to` | yes | — | Destination station name (foreign cities should include the country, e.g. `"München; Německo"`) |
| `date` | no | today | Departure date (date picker, ISO `YYYY-MM-DD`) |
| `time` | no | now + 2 h | Departure time (`HH:MM`) |
| `maxChanges` | no | `4` | Maximum allowed transfers per connection |
| `onlyDirectConnections` | no | `false` | Only return connections without transfers |
| `serviceClass` | no | `Class2` | `Class1`, `Class2`, or `ClassBusiness` |
| `maxResults` | no | `20` | Maximum number of connections to push to the dataset |
| `fetchPrices` | no | `true` | Whether to fetch the price for each connection |

#### Example input

```json
{
    "from": "Praha hl.n.",
    "to": "Copenhagen",
    "date": "2026-05-14",
    "time": "00:00",
    "onlyDirectConnections": true,
    "maxResults": 20,
    "fetchPrices": true
}
````

### Output

Each item in the dataset describes one connection.

#### Example item

```json
{
    "id": 80002583,
    "handle": 27910947,
    "from": "Praha hl.n.",
    "to": "Koebenhavn H",
    "departure": "2026-05-14T04:31:00.000Z",
    "arrival": "2026-05-14T17:38:00.000Z",
    "timeLengthMinutes": 787,
    "changesCount": 0,
    "price": 4280,
    "trains": [
        {
            "name": "rj 384 Berliner",
            "number": "384",
            "carrier": "ČD",
            "endStation": "Hamburg-Altona",
            "from": "Praha hl.n.",
            "to": "Koebenhavn H",
            "departure": "2026-05-14T04:31:00.000Z",
            "arrival": "2026-05-14T17:38:00.000Z",
            "timeLengthMinutes": 787,
            "distanceKilometres": 1124,
            "delay": -1,
            "waitTime": 0,
            "occupancyLevel": 0,
            "description": "railjet (Praha hl.n. – Hamburg-Altona)"
        }
    ]
}
```

`price` is in CZK; `null` means the price could not be retrieved (sold out, no ticketing available,
or `fetchPrices: false`). `changesCount` is `0` for direct connections.

### Pricing

The actor uses Apify pay-per-event pricing — one `search-result` event is charged for every
connection pushed to the dataset.

### Agentic use

The actor is built for use by AI agents:

- **Structured input schema.** Every input has a title, type, description, and validation rules so an
  agent can fill it in correctly without extra prompting.
- **Structured output schema.** Each dataset item has a stable, typed shape — agents can read fields
  like `departure`, `price`, or `changesCount` without parsing prose.
- **ISO timestamps.** Departures and arrivals are emitted as ISO 8601 UTC strings (`2026-05-14T04:31:00.000Z`),
  ready to be diffed, sorted, or compared.
- **Numeric quantities.** `timeLengthMinutes`, `distanceKilometres`, `changesCount`, `price` are
  numbers, not formatted strings — no parsing of "2 hod 48 min" or "213 km" required.
- **Predictable output.** Connections are returned in chronological order; duplicates are removed;
  gaps in the cd.cz timetable are skipped automatically up to `maxResults`.
- **Event-level cost control.** Pay-per-event billing means an agent that sets a small `maxResults`
  pays only for what it consumes.

Typical agent prompts that map cleanly onto this actor:

- *"Find the cheapest train from Praha to Brno tomorrow morning."*
- *"How long does the direct train from Praha to Berlin take, and when does the next one leave?"*
- *"List all direct overnight trains from Praha to Copenhagen in the next two weeks."*

The agent populates the input, runs the actor, then reads the resulting dataset items directly —
no scraping, no HTML, no string parsing.

# Actor input Schema

## `from` (type: `string`):

Departure station name (e.g. "Praha", "Aš město"). Czech diacritics are supported.

## `to` (type: `string`):

Destination station name. Foreign destinations should include the country (e.g. "München; Německo").

## `date` (type: `string`):

Departure date. Leave empty to use today + 2 hours.

## `time` (type: `string`):

Time in HH:MM (24h) format. Leave empty to use the current time + 2 hours.

## `maxChanges` (type: `integer`):

Maximum allowed train changes per connection.

## `onlyDirectConnections` (type: `boolean`):

If enabled, only connections without transfers are searched.

## `serviceClass` (type: `string`):

Travel class.

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

Maximum number of connections to push to the dataset. The actor stops after this many items.

## `fetchPrices` (type: `boolean`):

If enabled, the price for each connection is fetched. Disabling speeds up the actor at the cost of missing price information.

## Actor input object example

```json
{
  "from": "Praha",
  "to": "München; Německo",
  "maxChanges": 4,
  "onlyDirectConnections": false,
  "serviceClass": "Class2",
  "maxResults": 20,
  "fetchPrices": true
}
```

# Actor output Schema

## `connections` (type: `string`):

Default dataset items — one entry per train connection, each with the train legs and the price in CZK.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("jindrich.bar/ceske-drahy-connections").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("jindrich.bar/ceske-drahy-connections").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 '{}' |
apify call jindrich.bar/ceske-drahy-connections --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=jindrich.bar/ceske-drahy-connections",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "České Dráhy Connections Scraper",
        "description": "Scrape train connections from České Dráhy (Czech state railways) with departure dates, prices, train types, and more.",
        "version": "0.0",
        "x-build-id": "Rw7kbyrKjh29qKrJ5"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/jindrich.bar~ceske-drahy-connections/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-jindrich.bar-ceske-drahy-connections",
                "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/jindrich.bar~ceske-drahy-connections/runs": {
            "post": {
                "operationId": "runs-sync-jindrich.bar-ceske-drahy-connections",
                "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/jindrich.bar~ceske-drahy-connections/run-sync": {
            "post": {
                "operationId": "run-sync-jindrich.bar-ceske-drahy-connections",
                "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",
                "required": [
                    "from",
                    "to"
                ],
                "properties": {
                    "from": {
                        "title": "From station",
                        "type": "string",
                        "description": "Departure station name (e.g. \"Praha\", \"Aš město\"). Czech diacritics are supported.",
                        "default": "Praha"
                    },
                    "to": {
                        "title": "To station",
                        "type": "string",
                        "description": "Destination station name. Foreign destinations should include the country (e.g. \"München; Německo\").",
                        "default": "München; Německo"
                    },
                    "date": {
                        "title": "Departure date",
                        "type": "string",
                        "description": "Departure date. Leave empty to use today + 2 hours."
                    },
                    "time": {
                        "title": "Departure time",
                        "pattern": "^\\d{1,2}:\\d{2}$",
                        "type": "string",
                        "description": "Time in HH:MM (24h) format. Leave empty to use the current time + 2 hours."
                    },
                    "maxChanges": {
                        "title": "Max transfers",
                        "minimum": 0,
                        "maximum": 10,
                        "type": "integer",
                        "description": "Maximum allowed train changes per connection.",
                        "default": 4
                    },
                    "onlyDirectConnections": {
                        "title": "Only direct connections",
                        "type": "boolean",
                        "description": "If enabled, only connections without transfers are searched.",
                        "default": false
                    },
                    "serviceClass": {
                        "title": "Service class",
                        "enum": [
                            "Class1",
                            "Class2",
                            "ClassBusiness"
                        ],
                        "type": "string",
                        "description": "Travel class.",
                        "default": "Class2"
                    },
                    "maxResults": {
                        "title": "Max results",
                        "minimum": 1,
                        "maximum": 1000,
                        "type": "integer",
                        "description": "Maximum number of connections to push to the dataset. The actor stops after this many items.",
                        "default": 20
                    },
                    "fetchPrices": {
                        "title": "Fetch prices",
                        "type": "boolean",
                        "description": "If enabled, the price for each connection is fetched. Disabling speeds up the actor at the cost of missing price information.",
                        "default": true
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
