# SJ Scraper - Swedish Train Fares & Schedules (`studio-amba/sj-scraper`) Actor

Scrape train schedules, fares, and availability from SJ (sj.se), Sweden's national railway. Extract Snabbtag, InterCity, and regional train data for any Swedish route. No login required.

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

## Pricing

from $1.20 / 1,000 result scrapeds

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

### How to scrape SJ data

**SJ Scraper** extracts train schedules, ticket fares, availability, and journey details from [SJ](https://www.sj.se) — the official booking platform of Sweden's national railway operator. SJ operates high-speed (Snabbtag/X2000), InterCity, regional, and night train services across Sweden and to neighboring countries.

This Actor uses Playwright to navigate the SJ search interface, extract train results including departure times, prices in SEK, train types, and travel classes, and return structured data ready for analysis, fare monitoring, or integration with your travel platform. **No login or cookies required.**

### Why use SJ Scraper?

- **Fare monitoring** — Track ticket prices across routes and dates to find the best deals or monitor fare trends over time.
- **Travel research** — Compare routes, durations, and train types (Snabbtag, InterCity, Regional) for any Swedish destination.
- **Market intelligence** — Collect structured pricing data for competitive analysis in the Scandinavian travel industry.
- **Schedule tracking** — Monitor train schedules and connections for commuter or business travel planning.
- **API access** — Get SJ train data via Apify API, webhooks, or scheduled runs. Integrate with Zapier, Make, Google Sheets, or your own applications.

### What data can you extract from SJ?

| Field | Description |
|---|---|
| trainNumber | SJ train number identifier |
| trainType | Service type (SJ Snabbtag, SJ InterCity, SJ Regional, X2000, etc.) |
| departureStation | Departure station or city |
| arrivalStation | Arrival station or city |
| departureTime | Departure time (HH:mm) |
| arrivalTime | Arrival time (HH:mm) |
| duration | Total travel time (e.g., 3h 5min) |
| price | Ticket price in SEK |
| currency | Currency code (SEK) |
| travelClass | Seat class (1st, 2nd) |
| changes | Number of transfers |
| url | Source URL |
| scrapedAt | Timestamp of extraction |

### How to use SJ Scraper

1. Go to the SJ Scraper [input page](https://console.apify.com/actors/sj-scraper/input).
2. Enter your **origin** station (e.g., Stockholm) and **destination** station (e.g., Goteborg).
3. Optionally set a **departure date** in YYYY-MM-DD format. If left empty, defaults to 14 days from today.
4. Set the number of **passengers** (default: 1).
5. Configure **max results** to limit the number of train results returned.
6. Click **Start** and wait for the run to complete.
7. Download your data from the **Dataset** tab in JSON, CSV, Excel, or HTML format.

### Input parameters

| Parameter | Type | Default | Description |
|---|---|---|---|
| origin | string | Stockholm | Departure city or station name |
| destination | string | Goteborg | Arrival city or station name |
| departureDate | string | 14 days from today | Travel date (YYYY-MM-DD) |
| passengers | integer | 1 | Number of adult passengers (1-9) |
| maxResults | integer | 50 | Maximum results to return |
| proxyConfiguration | object | Residential SE | Proxy settings (residential recommended) |

#### Example input

```json
{
    "origin": "Stockholm",
    "destination": "Goteborg",
    "departureDate": "2026-07-15",
    "passengers": 1,
    "maxResults": 20
}
```

### Output example

```json
{
    "trainNumber": "525",
    "trainType": "SJ Snabbtag",
    "departureStation": "Stockholm",
    "arrivalStation": "Goteborg",
    "departureTime": "06:25",
    "arrivalTime": "09:30",
    "duration": "3h 5min",
    "price": 345,
    "currency": "SEK",
    "travelClass": "2nd",
    "changes": 0,
    "url": "https://www.sj.se/en",
    "scrapedAt": "2026-06-09T10:30:00.000Z"
}
```

### How much does it cost to scrape SJ?

A typical run searching one route returns 10-30 train results and costs approximately **$0.10-0.25** in Apify platform credits, depending on proxy usage and result count. The Actor uses Playwright (browser-based) which consumes more compute than HTTP-only scrapers, but this is necessary because SJ.se is a JavaScript single-page application.

To keep costs down:

- Set `maxResults` to only what you need.
- Use a specific date rather than leaving it to default.
- Schedule runs during off-peak hours for faster loading.

### Supported routes

SJ covers all major Swedish rail routes and some international connections:

- **High-speed (SJ Snabbtag / X2000)** — Stockholm-Goteborg, Stockholm-Malmo, Stockholm-Sundsvall, Goteborg-Malmo, Stockholm-Karlstad, and more.
- **InterCity** — Medium and long-distance routes across Sweden.
- **Regional** — Local and regional connections in Swedish regions.
- **Night train (SJ Nattag)** — Overnight services to northern Sweden (Lulea, Kiruna, Narvik).
- **International** — Stockholm-Copenhagen, Stockholm-Oslo, Goteborg-Copenhagen, Malmo-Copenhagen.

### Tips for best results

- **Use residential proxies** — SJ.se is a modern JavaScript SPA. Residential proxies with SE country code provide the best success rate.
- **Set realistic dates** — SJ typically shows results for dates up to 3 months in advance. Past dates or dates too far in the future will return no results.
- **Use common station names** — Major cities like Stockholm, Goteborg, Malmo, Uppsala, Linkoping, and Lund work well. For smaller stations, use the official SJ station name.
- **Run during business hours (CET)** — SJ.se tends to respond faster during European daytime hours.

### Integrations

Connect SJ Scraper to your workflow with:

- **Apify API** — Call programmatically from any language.
- **Webhooks** — Get notified when a run completes.
- **Scheduled runs** — Monitor fares daily or weekly.
- **Zapier / Make** — No-code integration with 5000+ apps.
- **Google Sheets** — Export results directly to a spreadsheet.

### FAQ

#### Is it legal to scrape SJ?

This Actor extracts publicly available train schedule and pricing information that any visitor can see on sj.se. No login, authentication, or account is required. Always ensure your use case complies with applicable laws and SJ's terms of service.

#### Why did my run return zero results?

SJ.se is a JavaScript SPA which may block automated requests. Make sure you are using residential proxies with SE country code. Also verify that your origin and destination station names are valid and your departure date is in the future.

#### Can I scrape multiple routes in one run?

Currently the Actor searches one route per run. To scrape multiple routes, trigger separate runs with different origin/destination combinations using the Apify API or scheduler.

#### How often is pricing data updated?

SJ updates prices dynamically based on demand and booking period. For accurate fare tracking, schedule runs at consistent times (e.g., daily at 8:00 AM CET).

#### What train operators are covered?

The scraper covers SJ-operated services (Snabbtag, InterCity, Regional, Night Train). Other operators visible on sj.se such as MTRX or Vy may also appear in results when available on the same routes.

### Support and feedback

If you encounter issues or have feature requests, please open an issue in the [Issues tab](https://console.apify.com/actors/sj-scraper/issues). For custom scraping solutions, reach out via the Actor's page on the Apify Store.

# Actor input Schema

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

Departure city or station name (e.g., Stockholm, Goteborg, Malmo, Uppsala, Linkoping).

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

Arrival city or station name (e.g., Goteborg, Stockholm, Malmo, Lund, Norrkoping).

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

Travel date in YYYY-MM-DD format. Defaults to 14 days from today if not set.

## `passengers` (type: `integer`):

Number of adult passengers.

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

Maximum number of train results to return.

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

Proxy settings. Residential proxies with SE country code recommended for best reliability.

## Actor input object example

```json
{
  "origin": "Stockholm",
  "destination": "Goteborg",
  "passengers": 1,
  "maxResults": 50,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "SE"
  }
}
```

# Actor output Schema

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

No description

# 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": "Stockholm",
    "destination": "Goteborg",
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "SE"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("studio-amba/sj-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": "Stockholm",
    "destination": "Goteborg",
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "SE",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("studio-amba/sj-scraper").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 '{
  "origin": "Stockholm",
  "destination": "Goteborg",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "SE"
  }
}' |
apify call studio-amba/sj-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,studio-amba/sj-scraper"
        }
    }
}
```

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/PbIkz8IjgVgtxKb2O/builds/CluOnsObe0jOf1N0n/openapi.json
