# Mlb Stats Scraper (`fabri.ce/mlb-stats-scraper`) Actor

Get official MLB player stats, team rosters, schedules, standings and league leaders. Search by player or team name, no need for internal IDs. No login. Built for fantasy baseball players, bettors, analysts and journalists who need clean, accurate baseball data fast.

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

## Pricing

from $3.50 / 1,000 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/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

Extract official MLB baseball data: **player profiles, team rosters, schedules, standings,
and league leaders**, as clean, structured records. **Search by player and team name.** No
need to know internal numeric IDs. No login, no account, no manual copying.

### 🎯 Who uses it?

#### 🎮 Fantasy baseball players

Pull season stats and rosters by name to set weekly lineups. No ID lookups first.

#### 🎲 Bettors & model builders

Build predictive models from season and career hitting, pitching, and fielding lines.

#### 📊 Analysts & researchers

Track standings, streaks, and league leaders across a season or a player's whole career.

#### ✍️ Journalists & content creators

Pull accurate stat lines and schedules for game previews, recaps, and player profiles.

### ✨ What it does

- **Player profiles:** bio (age, bats/throws, height, weight, birthplace, MLB debut) plus season
  or career hitting, pitching, or fielding stats, auto-detected by position, or forced to one
  group.
- **Teams:** abbreviation, league, division, venue, and (optionally) the full current roster.
- **Schedule:** games by date, date range, or team, with final scores, status, each team's
  record at the time, probable pitchers, and weather. Turn on box scores for the inning-by-inning
  line score, hits/errors, and the winning/losing/save pitcher.
- **Standings:** division rank, win/loss record, games back, streak, run differential, magic
  number.
- **League leaders:** the top players in any stat category (home runs, ERA, batting average,
  strikeouts, saves, and more), ranked.
- **Find players and teams by name**, like "Aaron Judge" or "Yankees", or pass numeric IDs
  directly if you already have them from a previous run.
- **Player headshots, team logos, and a link to the official profile page** on every row.
- Heights/weights are normalized to metric (cm / kg) alongside the original record.

### 📦 What data you get

| Entity | Useful fields |
| --- | --- |
| Player | Name, age, position, bats/throws, team, season or career hitting/pitching/fielding stats, height, weight, birthplace, MLB debut date, headshot photo, profile link. |
| Team | Name, abbreviation, league, division, venue, first year of play, logo, and the full current roster (name, position, jersey number, status). |
| Game | Away/home team, score, winner, status, date, venue, each team's record, probable pitchers, weather. With box scores on: inning-by-inning line score, hits/errors, and winning/losing/save pitcher. |
| Standing | Team, division rank, W-L record, win %, games back, streak, runs scored/allowed, magic number. |
| Leader | Rank, player, team, stat category and value. |

Every record includes `scraped_at` (UTC) and `source`. Download your dataset from Apify as CSV,
JSON, Excel, or XML.

### 💡 Use cases

#### 🎮 Set a fantasy lineup from current stats

```json
{
  "mode": "players",
  "playerNames": ["Shohei Ohtani", "Mookie Betts", "Juan Soto"]
}
```

#### 🎲 Compare a pitcher's career vs. this season

```json
{
  "mode": "players",
  "playerNames": ["Gerrit Cole"],
  "statType": "career"
}
```

#### 📅 Get every game a team played in a date range

```json
{
  "mode": "schedule",
  "teamNames": ["Yankees"],
  "fromDate": "2026-06-01",
  "toDate": "2026-06-30"
}
```

#### 📊 Check the standings

```json
{
  "mode": "standings",
  "league": "AL"
}
```

#### 🏆 Get the home run leaderboard

```json
{
  "mode": "leaders",
  "leaderCategory": "homeRuns",
  "maxItems": 25
}
```

#### ⚾ Get full box scores for a day's games

```json
{
  "mode": "schedule",
  "date": "2026-06-15",
  "includeBoxScore": true
}
```

#### 🧢 Pull a full team roster

```json
{
  "mode": "teams",
  "teamNames": ["Dodgers"],
  "includeRoster": true
}
```

### ⚙️ How the input is organised

The input form is split into four numbered sections. Every field's title says which mode(s) it
applies to, so it's always clear what to fill in and what to leave alone.

| Section | What it's for |
| --- | --- |
| **1 · What do you want to scrape?** | Pick one **type of data**: Player profiles, Teams, Schedule, Standings, or League leaders. |
| **2 · Who or what to get** | Fill in only what your mode needs: **player names or IDs** for Player profiles; **team names or IDs** for Teams and Schedule; a **date, date range, or team** for Schedule; a **league** (AL/NL/both) for Standings; a **stat category** (e.g. `homeRuns`, `era`) for League leaders. A **season** field is available for every mode except Schedule. |
| **3 · How much to collect** | **Maximum rows** for the whole run. |
| **4 · What to include** | Stat type (auto, hitting, pitching, or fielding) and season vs. career, for Player profiles. Whether to attach the full roster, for Teams. Whether to add box-score details, for Schedule. |

> **Apify Free plan:** every run is limited to a fixed 10-row sample. Upgrade your Apify plan to
> run your own settings.

### 🛡️ Limits & responsible use

This Actor collects only publicly available, official MLB statistics. It never signs in and
never accesses anything gated behind an account.

If a player, team, or game can't be found, that entry is skipped with a warning in the run log.
The rest of the run continues.

### 🧪 Local development

```powershell
bun install
bun run typecheck
bun test
bun run start
```

Test with a sample `storage/key_value_stores/default/INPUT.json`, e.g.:

```json
{ "mode": "players", "playerNames": ["Aaron Judge"], "maxItems": 5 }
```

# Actor input Schema

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

**Player profiles**: bio and season (or career) stats for one or more named players.
**Teams**: team info, optionally with the full current roster.
**Schedule**: games by date, date range, or team, with final scores.
**Standings**: current division standings.
**League leaders**: the top players in any stat category (home runs, ERA, batting average, etc).

*On the Apify **Free** plan every run is limited to a fixed 10-row sample; upgrade to run your own settings.*

## `playerNames` (type: `array`):

One or more player names, e.g. `Aaron Judge`. Matched by name against the official record. No need to know internal player IDs.

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

Already know the numeric player ID (e.g. from a previous run)? List them here. Can be combined with the names above.

## `teamNames` (type: `array`):

One or more team names, e.g. `Yankees` or `New York Yankees`. Leave empty in Teams mode to get all 30 teams. In Schedule mode, filters games to one team.

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

Already know the numeric team ID? List them here. Can be combined with the names above.

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

Games on this single date. Format: `YYYY-MM-DD`.

## `fromDate` (type: `string`):

Start of a date range. Format: `YYYY-MM-DD`.

## `toDate` (type: `string`):

End of a date range. Format: `YYYY-MM-DD`.

## `league` (type: `string`):

Which league's standings to get.

## `leaderCategory` (type: `string`):

The stat to rank by. Common ones: `homeRuns`, `avg`, `rbi`, `stolenBases`, `era`, `strikeouts`, `wins`, `saves`, `obp`, `slg`, `ops`, `whip`.

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

MLB season year, e.g. `2025`. Leave empty for the current season.

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

Stop once this many rows are in the dataset. Leave empty to get everything. *(Free plan: always capped at 10.)*

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

**Auto**: hitting stats for position players, pitching stats for pitchers (recommended). Or force one specific group for every player.

## `statType` (type: `string`):

**Season**: stats for one season (see "Season" above, or the current season). **Career**: lifetime totals.

## `includeRoster` (type: `boolean`):

Attach every player currently on the roster (name, position, jersey number) to each team's row.

## `includeBoxScore` (type: `boolean`):

Add the inning-by-inning line score, team hits/errors, and the winning/losing/save pitcher to each game. One extra lookup per game, so it's off by default for large date ranges. Turn it on for a handful of games.

## Actor input object example

```json
{
  "mode": "players",
  "playerNames": [
    "Aaron Judge",
    "Shohei Ohtani"
  ],
  "playerIds": [],
  "teamNames": [
    "Yankees",
    "Dodgers"
  ],
  "teamIds": [],
  "league": "both",
  "leaderCategory": "homeRuns",
  "maxItems": 10,
  "statGroup": "auto",
  "statType": "season",
  "includeRoster": true
}
```

# Actor output Schema

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

One row per player, team, game, standing, or leaderboard entry, depending on the selected mode.

# 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": "players",
    "playerNames": [
        "Aaron Judge",
        "Shohei Ohtani",
        "Mookie Betts",
        "Ronald Acuna Jr.",
        "Juan Soto",
        "Gerrit Cole",
        "Freddie Freeman",
        "Jose Ramirez",
        "Tarik Skubal",
        "Bobby Witt Jr."
    ],
    "playerIds": [],
    "teamNames": [],
    "teamIds": [],
    "league": "both",
    "leaderCategory": "homeRuns",
    "maxItems": 10,
    "statGroup": "auto",
    "statType": "season",
    "includeRoster": true,
    "includeBoxScore": false
};

// Run the Actor and wait for it to finish
const run = await client.actor("fabri.ce/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 = {
    "mode": "players",
    "playerNames": [
        "Aaron Judge",
        "Shohei Ohtani",
        "Mookie Betts",
        "Ronald Acuna Jr.",
        "Juan Soto",
        "Gerrit Cole",
        "Freddie Freeman",
        "Jose Ramirez",
        "Tarik Skubal",
        "Bobby Witt Jr.",
    ],
    "playerIds": [],
    "teamNames": [],
    "teamIds": [],
    "league": "both",
    "leaderCategory": "homeRuns",
    "maxItems": 10,
    "statGroup": "auto",
    "statType": "season",
    "includeRoster": True,
    "includeBoxScore": False,
}

# Run the Actor and wait for it to finish
run = client.actor("fabri.ce/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 '{
  "mode": "players",
  "playerNames": [
    "Aaron Judge",
    "Shohei Ohtani",
    "Mookie Betts",
    "Ronald Acuna Jr.",
    "Juan Soto",
    "Gerrit Cole",
    "Freddie Freeman",
    "Jose Ramirez",
    "Tarik Skubal",
    "Bobby Witt Jr."
  ],
  "playerIds": [],
  "teamNames": [],
  "teamIds": [],
  "league": "both",
  "leaderCategory": "homeRuns",
  "maxItems": 10,
  "statGroup": "auto",
  "statType": "season",
  "includeRoster": true,
  "includeBoxScore": false
}' |
apify call fabri.ce/mlb-stats-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fabri.ce/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/gcjGkuLafJcOFQe50/builds/bFS6Gs0ubIAbvCPFO/openapi.json
