# MLB Baseball Stats Scraper (`crawlerbros/mlb-baseball-stats-scraper`) Actor

Scrape the official MLB Stats API - comprehensive baseball data including teams, player batting/pitching stats, schedules, and standings. Official MLB data source, no authentication required.

- **URL**: https://apify.com/crawlerbros/mlb-baseball-stats-scraper.md
- **Developed by:** [Crawler Bros](https://apify.com/crawlerbros) (community)
- **Categories:** Automation, Developer tools, Integrations
- **Stats:** 10 total users, 0 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
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

## MLB Baseball Stats Scraper

Access comprehensive baseball data from the **official MLB Stats API** — player batting and pitching statistics, team standings, game schedules, and team info. No authentication required. Official MLB data updated in real-time during the season.

### What You Can Scrape

| Mode | Data |
|------|------|
| `getPlayerStats` | Season batting or pitching statistics for all players |
| `getStandings` | Division standings for AL and NL |
| `getSchedule` | Game schedule and results for a date range |
| `getTeams` | List all 30 MLB teams with league and division info |

### Input Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `mode` | select | `getPlayerStats` | What data to retrieve |
| `statGroup` | select | `hitting` | Type of stats: `hitting`, `pitching`, or `fielding` |
| `season` | integer | `2024` | MLB season year (2019–2024) |
| `teamId` | integer | — | Filter by MLB team ID (e.g. 147 = Yankees). Optional. |
| `startDate` | text | — | Start date YYYY-MM-DD for `getSchedule` mode |
| `endDate` | text | — | End date YYYY-MM-DD for `getSchedule` mode |
| `maxItems` | integer | `50` | Maximum records to return (1–500) |

### Output Fields

#### Player Stats (getPlayerStats)

| Field | Description |
|-------|-------------|
| `playerId` | MLB player identifier |
| `playerName` | Player full name |
| `teamId` | Team identifier |
| `teamName` | Team name |
| `position` | Primary field position |
| `season` | Season year |
| `gamesPlayed` | Games played |
| `atBats` | At bats |
| `hits` | Hits |
| `doubles` | Doubles |
| `triples` | Triples |
| `homeRuns` | Home runs |
| `rbi` | Runs batted in |
| `battingAverage` | Batting average (e.g. ".304") |
| `onBasePercentage` | On-base percentage |
| `sluggingPct` | Slugging percentage |
| `ops` | On-base plus slugging |
| `era` | Earned run average (pitchers) |
| `wins` | Pitcher wins |
| `losses` | Pitcher losses |
| `strikeouts` | Strikeouts |
| `mlbUrl` | Official MLB player page URL |
| `scrapedAt` | Timestamp of scraping |

#### Standings (getStandings)

| Field | Description |
|-------|-------------|
| `teamName` | Team name |
| `divisionName` | Division name (e.g. AL East) |
| `leagueName` | American League or National League |
| `wins` | Total wins |
| `losses` | Total losses |
| `pct` | Winning percentage |
| `gamesBack` | Games behind division leader |
| `divisionRank` | Rank within division |
| `streakCode` | Current streak (e.g. W5, L2) |
| `runsScored` | Total runs scored |
| `runsAllowed` | Total runs allowed |
| `runDifferential` | Run differential |

#### Schedule (getSchedule)

| Field | Description |
|-------|-------------|
| `gamePk` | Game primary key |
| `gameDate` | Game date/time (ISO 8601) |
| `officialDate` | Official game date (YYYY-MM-DD) |
| `homeTeam` | Home team name |
| `awayTeam` | Away team name |
| `homeScore` | Home team runs scored |
| `awayScore` | Away team runs scored |
| `status` | Game status (Final, In Progress, etc.) |
| `venue` | Stadium name |
| `mlbUrl` | Official MLB gameday page URL |

#### Teams (getTeams)

| Field | Description |
|-------|-------------|
| `teamId` | MLB team identifier |
| `name` | Full team name |
| `abbreviation` | 2–3 letter abbreviation (e.g. NYY) |
| `teamName` | Short team name (e.g. Yankees) |
| `locationName` | City/location |
| `leagueName` | American League or National League |
| `divisionName` | Division (e.g. AL East) |
| `venueName` | Home stadium name |
| `active` | Whether the team is active |
| `mlbUrl` | Official MLB team page URL |

### Example Configurations

**Get top 2024 batting stats (default, works for daily test):**
```json
{
  "mode": "getPlayerStats",
  "statGroup": "hitting",
  "season": 2024,
  "maxItems": 30
}
````

**Get 2024 pitching leaders:**

```json
{
  "mode": "getPlayerStats",
  "statGroup": "pitching",
  "season": 2024,
  "maxItems": 50
}
```

**Get Yankees 2024 batting stats:**

```json
{
  "mode": "getPlayerStats",
  "statGroup": "hitting",
  "season": 2024,
  "teamId": 147,
  "maxItems": 50
}
```

**Get 2024 final standings:**

```json
{
  "mode": "getStandings",
  "season": 2024,
  "maxItems": 30
}
```

**Get opening week 2024 schedule:**

```json
{
  "mode": "getSchedule",
  "season": 2024,
  "startDate": "2024-03-20",
  "endDate": "2024-03-27",
  "maxItems": 50
}
```

**Get all 30 MLB teams:**

```json
{
  "mode": "getTeams",
  "season": 2024,
  "maxItems": 30
}
```

### Common Team IDs

| Team | ID | Team | ID |
|------|----|------|----|
| New York Yankees | 147 | New York Mets | 121 |
| Boston Red Sox | 111 | Los Angeles Dodgers | 119 |
| Chicago Cubs | 112 | San Francisco Giants | 137 |
| Houston Astros | 117 | Atlanta Braves | 144 |
| Los Angeles Angels | 108 | Philadelphia Phillies | 143 |
| Chicago White Sox | 145 | Seattle Mariners | 136 |
| Toronto Blue Jays | 141 | Washington Nationals | 120 |

### Use Cases

- **Fantasy baseball** — pull hitting and pitching stats for player evaluation
- **Sports analytics** — aggregate season stats for modeling and predictions
- **Sports dashboards** — build standings and stats leaderboards
- **Historical research** — analyze player and team performance across seasons (2019–2024)
- **Data pipelines** — feed official MLB data into BI tools or databases

### Data Source

All data comes from the [official MLB Stats API](https://statsapi.mlb.com/api/v1/) — the same API used by MLB.com and major sports analytics platforms. The API is completely free and requires no authentication.

### FAQs

**Q: How current is the data?**
A: Standings and schedules update in real-time during the season. Player stats may have slight delays (typically updated daily).

**Q: What seasons are available?**
A: This scraper supports 2019–2024. The MLB Stats API has historical data going back to 1876, but stat coverage varies for older seasons.

**Q: How do I filter by team?**
A: Set `teamId` to the MLB team ID. For example, `teamId: 147` returns only New York Yankees stats. Leave blank for all teams.

**Q: What does `statGroup` control?**
A: It switches between `hitting` (batting stats), `pitching` (ERA, WHIP, wins), and `fielding` (errors, putouts, assists).

**Q: Is there a cost to use this scraper?**
A: No. The MLB Stats API is free and public. This scraper requires no proxy or API credentials and runs on the Apify free plan.

**Q: Can I get playoff stats?**
A: The `getPlayerStats` mode uses regular season (`R`) data. For playoff-specific stats, adjust the game type via the API parameters if needed in a custom setup.

# Actor input Schema

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

What data to fetch from the MLB Stats API.

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

Type of player stats to retrieve (for mode=getPlayerStats).

## `season` (type: `integer`):

MLB season year (e.g. 2024). Supported range: 2019–2024.

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

Filter by MLB team ID (e.g. 147 = Yankees, 111 = Red Sox). Optional — leave blank for all teams.

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

Start date for schedule range (e.g. '2024-04-01'). Used for mode=getSchedule.

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

End date for schedule range (e.g. '2024-04-07'). Used for mode=getSchedule.

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

Maximum number of records to return (1–500).

## Actor input object example

```json
{
  "mode": "getPlayerStats",
  "statGroup": "hitting",
  "season": 2024,
  "maxItems": 30
}
```

# Actor output Schema

## `mlbData` (type: `string`):

Dataset containing all scraped MLB records (teams, players, games, standings, or stats).

# 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 = {
    "mode": "getPlayerStats",
    "statGroup": "hitting",
    "season": 2024,
    "maxItems": 30
};

// Run the Actor and wait for it to finish
const run = await client.actor("crawlerbros/mlb-baseball-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 = {
    "mode": "getPlayerStats",
    "statGroup": "hitting",
    "season": 2024,
    "maxItems": 30,
}

# Run the Actor and wait for it to finish
run = client.actor("crawlerbros/mlb-baseball-stats-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 '{
  "mode": "getPlayerStats",
  "statGroup": "hitting",
  "season": 2024,
  "maxItems": 30
}' |
apify call crawlerbros/mlb-baseball-stats-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=crawlerbros/mlb-baseball-stats-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "MLB Baseball Stats Scraper",
        "description": "Scrape the official MLB Stats API - comprehensive baseball data including teams, player batting/pitching stats, schedules, and standings. Official MLB data source, no authentication required.",
        "version": "1.0",
        "x-build-id": "rtdk2LtOpQkCiouqd"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/crawlerbros~mlb-baseball-stats-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-crawlerbros-mlb-baseball-stats-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/crawlerbros~mlb-baseball-stats-scraper/runs": {
            "post": {
                "operationId": "runs-sync-crawlerbros-mlb-baseball-stats-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/crawlerbros~mlb-baseball-stats-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-crawlerbros-mlb-baseball-stats-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",
                "required": [
                    "mode"
                ],
                "properties": {
                    "mode": {
                        "title": "Mode",
                        "enum": [
                            "getPlayerStats",
                            "getStandings",
                            "getSchedule",
                            "getTeams"
                        ],
                        "type": "string",
                        "description": "What data to fetch from the MLB Stats API.",
                        "default": "getPlayerStats"
                    },
                    "statGroup": {
                        "title": "Stat Group",
                        "enum": [
                            "hitting",
                            "pitching",
                            "fielding"
                        ],
                        "type": "string",
                        "description": "Type of player stats to retrieve (for mode=getPlayerStats).",
                        "default": "hitting"
                    },
                    "season": {
                        "title": "Season (year)",
                        "minimum": 2019,
                        "maximum": 2024,
                        "type": "integer",
                        "description": "MLB season year (e.g. 2024). Supported range: 2019–2024.",
                        "default": 2024
                    },
                    "teamId": {
                        "title": "Team ID",
                        "minimum": 100,
                        "maximum": 999,
                        "type": "integer",
                        "description": "Filter by MLB team ID (e.g. 147 = Yankees, 111 = Red Sox). Optional — leave blank for all teams."
                    },
                    "startDate": {
                        "title": "Start Date (YYYY-MM-DD)",
                        "type": "string",
                        "description": "Start date for schedule range (e.g. '2024-04-01'). Used for mode=getSchedule."
                    },
                    "endDate": {
                        "title": "End Date (YYYY-MM-DD)",
                        "type": "string",
                        "description": "End date for schedule range (e.g. '2024-04-07'). Used for mode=getSchedule."
                    },
                    "maxItems": {
                        "title": "Max Items",
                        "minimum": 1,
                        "maximum": 500,
                        "type": "integer",
                        "description": "Maximum number of records to return (1–500).",
                        "default": 50
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
