# MLB Stats Scraper ⚾ Teams, Schedules, Rosters & Stats (`viralanalyzer/mlb-stats-scraper`) Actor

Scrape official Major League Baseball data from the MLB Stats API: all 30 teams, rosters, game schedules, scores, standings, and player hitting/pitching statistics. Fast, accurate, no API key required.

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

## Pricing

from $3.00 / 1,000 mlb stat records

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

Scrape official Major League Baseball data directly from the official **MLB Stats API**. Access all 30 MLB teams, full rosters, player info, real-time game schedules, final/live scores, and division & league standings — fast, 100% reliable, and with no API keys or browser automation needed.

***

### 🌟 Key Features

- **⚡ Direct Official API Connection:** Queries official MLB endpoints with sub-second response times and 99.9% uptime.
- **⚾ All 30 MLB Teams & Venues:** Team names, abbreviations, divisions, leagues, and stadium/venue details.
- **👥 Active Rosters & Player Details:** Jersey numbers, positions, roster status, and player IDs.
- **🏆 Complete Standings:** Wins, losses, winning percentages, games back, streaks, run differential, and home/away splits.
- **📅 Schedules & Scores:** Matchups, game status, inning linescores, hits, errors, and winner/loser stats.
- **🛡️ 100% Free of Bot-Blocks:** Pure public JSON API access with built-in UAG-SG guardrails.

***

### 📥 Input Parameters

| Parameter | Type | Default | Description |
|---|---|---|---|
| `mode` | String (select) | `"standings"` | Data to scrape: `teams`, `roster`, `schedule`, `standings`, or `all`. |
| `season` | Integer | `2026` | MLB Season year. |
| `teamIds` | Array of strings | `[]` | Optional team IDs or names (e.g. `["Yankees", "Dodgers"]` or `[147, 119]`). |
| `startDate` | String | `""` | Start date for schedules/scores (`YYYY-MM-DD`). |
| `endDate` | String | `""` | End date for schedules/scores (`YYYY-MM-DD`). |
| `maxResults` | Integer | `100` | Maximum number of records to return. |

***

### 📤 Output Formats

#### Standings Record

```json
{
  "type": "standing",
  "id": "mlb-standing-147-2026",
  "teamId": 147,
  "teamName": "New York Yankees",
  "league": "American League",
  "division": "American League East",
  "divisionRank": "1",
  "leagueRank": "1",
  "wins": 75,
  "losses": 45,
  "winningPercentage": ".625",
  "gamesBack": "-",
  "streak": "W3",
  "runsScored": 612,
  "runsAllowed": 480,
  "runDifferential": 132,
  "homeRecord": "40-20",
  "awayRecord": "35-25",
  "lastTen": "7-3",
  "season": 2026,
  "source": "Official MLB Stats API",
  "scrapedAt": "2026-08-17T05:34:00.000Z"
}
```

#### Game Schedule Record

```json
{
  "type": "game",
  "id": "mlb-game-745120",
  "gameId": 745120,
  "gameDate": "2026-08-16T23:05:00Z",
  "officialDate": "2026-08-16",
  "status": "Final",
  "isFinal": true,
  "homeTeam": { "id": 147, "name": "New York Yankees", "score": 6, "isWinner": true },
  "awayTeam": { "id": 111, "name": "Boston Red Sox", "score": 3, "isWinner": false },
  "venue": "Yankee Stadium",
  "linescore": { "homeHits": 9, "homeErrors": 0, "awayHits": 5, "awayErrors": 1 },
  "season": 2026,
  "source": "Official MLB Stats API",
  "scrapedAt": "2026-08-17T05:34:00.000Z"
}
```

***

### 💰 Pricing

This Actor uses **Pay Per Event (PPE)** pricing:

| Event | Price |
|---|---|
| `stat-record` | **$0.005 per item** ($5.00 / 1,000 stats/games) |

***

### 🔗 Related Actors

- [Sports Betting & Odds Intelligence](https://apify.com/viralanalyzer/sports-betting-intelligence) — Live odds and arbitrage for MLB, NBA, NFL, Soccer.

# Actor input Schema

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

Type of MLB data to scrape.

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

MLB season year (e.g. 2026, 2025, 2024). Defaults to current year.

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

Optional list of team IDs (e.g. 147 for NY Yankees, 119 for LA Dodgers, 111 for Red Sox) or team names ('Yankees', 'Dodgers', 'Red Sox'). If empty, all teams are processed.

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

For 'schedule' mode: Start date for game schedule/scores (e.g. '2026-04-01').

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

For 'schedule' mode: End date for game schedule/scores (e.g. '2026-10-31').

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

Maximum number of records to push to the dataset.

## Actor input object example

```json
{
  "mode": "standings",
  "season": 2026,
  "teamIds": [
    "Yankees",
    "Dodgers"
  ],
  "startDate": "2026-04-01",
  "endDate": "2026-10-31",
  "maxResults": 100
}
```

# Actor output Schema

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

Dataset containing all scraped MLB statistics.

# 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("viralanalyzer/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 = {}

# Run the Actor and wait for it to finish
run = client.actor("viralanalyzer/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 '{}' |
apify call viralanalyzer/mlb-stats-scraper --silent --output-dataset

```

## MCP server setup

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