# MLB Stats Scraper - Teams, Rosters, Scores & Standings (`seemuapps/mlb-stats-scraper`) Actor

Scrape MLB teams, team rosters with player season stats, game scores and schedules, and division/league standings. No API key required.

- **URL**: https://apify.com/seemuapps/mlb-stats-scraper.md
- **Developed by:** [Andrew](https://apify.com/seemuapps) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$4.00 / 1,000 mlb data records

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?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## MLB Stats Scraper - Teams, Rosters, Scores & Standings

Extract Major League Baseball data on demand — teams, rosters, player season stats, game scores, box scores, standings, and stat leaderboards — all from one actor with seven scraping modes.

### What you get

| Mode | What it returns |
|------|------------------|
| `teams` | All 30 MLB teams: id, name, abbreviation, division, league, home venue |
| `roster` | A team's active 26-man roster with jersey number, position, and current-season batting or pitching stats per player |
| `schedule` | Games for a date or date range: status (scheduled/live/final), venue, home/away teams and scores, game type |
| `standings` | Division and league standings: rank, wins, losses, win %, games back, streak — one or more seasons |
| `playerStats` | Full season hitting, pitching, or fielding stat lines for specific players or entire team rosters, across one or more seasons |
| `gameDetails` | Per-team box score lines (2 rows per game): runs, hits, doubles, triples, HR, RBI, walks, strikeouts, errors, innings pitched, ERA |
| `leaders` | Ranked statistical leaderboards for any hitting, pitching, or fielding category |

### Use cases

- Fantasy baseball — pull live rosters, season stats, and leaderboards to research lineup and waiver-wire decisions
- Sports betting models — feed schedules, box scores, and standings context into a line-setting or line-shopping model
- Sports media — power a live scoreboard, standings widget, or player-stat lookup
- Data science and analytics — build a historical or current-season dataset across multiple seasons for modeling and reporting
- Dashboards — refresh a team or league dashboard with live scores, standings, and stat leaders on a schedule

### How to use

1. Choose a **Mode**: `teams`, `roster`, `schedule`, `standings`, `playerStats`, `gameDetails`, or `leaders`
2. For **roster** mode, set **Team ID** (e.g. `147` for the New York Yankees) or **Team abbreviation** (e.g. `NYY`) — run `teams` mode first if you need to look up an ID
3. For **schedule** and **gameDetails** modes, set **Date** (`YYYY-MM-DD`) for a single day, or **Start date** / **End date** for a range — leave blank for today's games. Optionally set **Game type** to filter to Regular Season, Spring Training, or a specific postseason round. `gameDetails` mode can instead take explicit **Game PKs** to box-score exact games.
4. For **standings** mode, set **Seasons** (defaults to the current year) and **League** (American, National, or both)
5. For **playerStats** mode, set **Player IDs** (specific players) or **Team IDs** (whole rosters), **Stat group** (hitting/pitching/fielding), and **Seasons**
6. For **leaders** mode, set **Leader categories** (e.g. `homeRuns`, `battingAverage`, `earnedRunAverage`), **Stat group**, and **Seasons**
7. Set **Max items** to cap the number of dataset rows (default 100; 0 = no cap)
8. Run the actor — results appear in the **Dataset** tab

### Output format

Every record includes a `recordType` field (`team`, `player`, `game`, `standing`, `playerStat`, `gameDetail`, or `leader`) so mixed-mode datasets stay easy to filter. Example roster record:

```json
{
  "recordType": "player",
  "playerId": 592789,
  "fullName": "Gerrit Cole",
  "jerseyNumber": "45",
  "position": "Pitcher",
  "positionAbbreviation": "P",
  "teamId": 147,
  "statsGroup": "pitching",
  "season": "2026",
  "era": "3.15",
  "wins": 12,
  "losses": 6,
  "strikeOuts": 198,
  "whip": "1.05"
}
```

Example `leaders` record:

```json
{
  "recordType": "leader",
  "category": "homeRuns",
  "statGroup": "hitting",
  "season": "2026",
  "gameType": "R",
  "rank": 1,
  "value": "40",
  "playerId": 656941,
  "playerName": "Kyle Schwarber",
  "teamId": 143,
  "teamName": "Philadelphia Phillies",
  "leagueId": 104,
  "leagueName": "National League"
}
```

Example `gameDetail` record:

```json
{
  "recordType": "gameDetail",
  "gamePk": 824911,
  "officialDate": "2026-08-31",
  "status": "Final",
  "gameType": "R",
  "venue": "Truist Park",
  "teamId": 144,
  "teamName": "Atlanta Braves",
  "homeAway": "home",
  "opponentTeamName": "San Francisco Giants",
  "runs": 3,
  "hits": 9,
  "homeRuns": 1,
  "strikeOuts": 10,
  "errors": 0,
  "pitchingInningsPitched": "9.0",
  "pitchingEra": "3.58"
}
```

Example `standing` record:

```json
{
  "recordType": "standing",
  "season": "2026",
  "leagueName": "American League",
  "divisionName": "American League East",
  "teamName": "Rays",
  "wins": 82,
  "losses": 55,
  "winningPercentage": ".599",
  "gamesBack": "-",
  "divisionRank": "1"
}
```

# Actor input Schema

## `mode` (type: `string`):

What to scrape. 'teams' lists all MLB teams. 'roster' returns a team's active roster with player season stats. 'schedule' returns games/scores for a date or date range. 'standings' returns division and league standings. 'playerStats' returns full season stat lines for specific players or teams. 'gameDetails' returns per-team box score lines (2 rows per game). 'leaders' returns ranked statistical leaderboards.

## `teamId` (type: `integer`):

MLB team ID for 'roster' mode, e.g. 147 for the New York Yankees. Run 'teams' mode first to look up IDs. Ignored in other modes.

## `teamAbbreviation` (type: `string`):

Optional alternative to Team ID for 'roster' mode, e.g. 'NYY'. Used only if Team ID is not set. Ignored in other modes.

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

Single date in YYYY-MM-DD format for 'schedule' mode, or for 'gameDetails' mode when Game PKs are not set. Leave empty to use today's date, or set Start Date / End Date instead for a range. Ignored in other modes.

## `startDate` (type: `string`):

Start of a date range (YYYY-MM-DD) for 'schedule' mode or for 'gameDetails' mode when Game PKs are not set. Requires End Date to also be set; overrides Date when both are present. Ignored in other modes.

## `endDate` (type: `string`):

End of a date range (YYYY-MM-DD) for 'schedule' mode or for 'gameDetails' mode when Game PKs are not set. Requires Start Date to also be set. Ignored in other modes.

## `gameType` (type: `string`):

Filters games by MLB game type in 'schedule' mode and in 'gameDetails' mode (when Game PKs are not set), and tags the game type used for 'leaders' mode. Default is Regular Season. Note: MLB has no single generic 'postseason' filter — select the specific postseason round (Wild Card, Division Series, LCS, or World Series).

## `leagueId` (type: `string`):

Which league's standings to return in 'standings' mode. Ignored in other modes.

## `seasons` (type: `array`):

Four-digit season years, e.g. \['2025','2026']. Used by 'playerStats', 'standings', and 'leaders' modes — when multiple seasons are given, each mode loops over all of them and tags every output row with its 'season' field so a multi-season run stays separable in one dataset. Leave empty to use the current season. In 'roster' mode only the first season is used (roster reflects the current team, not a historical one). Ignored in 'teams', 'schedule', and 'gameDetails' modes.

## `teamIds` (type: `array`):

MLB team IDs for 'playerStats' mode. Every player on each team's active roster gets a stat line for the selected Stat group and each selected season. Ignored if Player IDs is set. Ignored in other modes.

## `playerIds` (type: `array`):

MLB player IDs for 'playerStats' mode, e.g. \['592450'] for Aaron Judge. When set, fetches these specific players' stats directly instead of resolving via Team IDs. Ignored in other modes.

## `statGroup` (type: `string`):

Which stat category to return in 'playerStats' and 'leaders' modes. Ignored in other modes.

## `leaderCategories` (type: `array`):

MLB stat leader category keys for 'leaders' mode, e.g. \['homeRuns','battingAverage','earnedRunAverage','strikeouts','saves']. Must match the selected Stat group (hitting categories with statGroup=hitting, pitching categories with statGroup=pitching, etc). Defaults to \['homeRuns']. Ignored in other modes.

## `gamePks` (type: `array`):

Specific MLB game IDs (gamePk) for 'gameDetails' mode, e.g. \['824911']. When set, fetches box scores for exactly these games instead of deriving games from Date / Start Date / End Date. Ignored in other modes.

## `maxItems` (type: `integer`):

Maximum dataset records to return in this run. 0 = no cap. 'gameDetails' mode produces 2 rows per game, so its effective game count is roughly half this value (also safety-capped at 50 games when unlimited). Mainly relevant for 'roster', 'schedule', 'playerStats', 'gameDetails', and 'leaders' modes; 'teams' always returns 30 or fewer and 'standings' returns one record per team per season.

## Actor input object example

```json
{
  "mode": "teams",
  "teamId": 147,
  "gameType": "R",
  "leagueId": "BOTH",
  "seasons": [],
  "teamIds": [],
  "playerIds": [],
  "statGroup": "hitting",
  "leaderCategories": [
    "homeRuns"
  ],
  "gamePks": [],
  "maxItems": 100
}
```

# Actor output Schema

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

Teams mode: id, name, abbreviation, division, league, venue. Roster mode: playerId, fullName, jerseyNumber, position, plus season batting or pitching stats. Schedule mode: gamePk, gameDate, status, home/away teams and scores, venue. Standings mode: team, division, league, wins, losses, winPct, gamesBack, season. Player stats mode: playerId, fullName, teamId, statGroup, season, plus the full hitting/pitching/fielding stat block. Game details mode: gamePk, teamId, homeAway, batting/pitching/fielding line for that team in that game (2 rows per game). Leaders mode: category, rank, value, playerName, teamName, season.

# 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 = {
    "teamId": 147,
    "teamAbbreviation": "",
    "date": "",
    "startDate": "",
    "endDate": "",
    "seasons": [],
    "teamIds": [],
    "playerIds": [],
    "leaderCategories": [
        "homeRuns"
    ],
    "gamePks": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("seemuapps/mlb-stats-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 = {
    "teamId": 147,
    "teamAbbreviation": "",
    "date": "",
    "startDate": "",
    "endDate": "",
    "seasons": [],
    "teamIds": [],
    "playerIds": [],
    "leaderCategories": ["homeRuns"],
    "gamePks": [],
}

# Run the Actor and wait for it to finish
run = client.actor("seemuapps/mlb-stats-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 '{
  "teamId": 147,
  "teamAbbreviation": "",
  "date": "",
  "startDate": "",
  "endDate": "",
  "seasons": [],
  "teamIds": [],
  "playerIds": [],
  "leaderCategories": [
    "homeRuns"
  ],
  "gamePks": []
}' |
apify call seemuapps/mlb-stats-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,seemuapps/mlb-stats-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/L2Yv2GKFkyW9T1Kza/builds/KrZfP0bQ3b9eHnOA9/openapi.json
