# Basketball Reference Scraper - NBA Player Stats (`lulzasaur/basketball-reference-scraper`) Actor

Scrape Basketball-Reference.com for NBA/ABA player stats. Index mode gets 5,400+ players with bio data. Detailed mode adds full career per-game stats, advanced stats, and playoff stats.

- **URL**: https://apify.com/lulzasaur/basketball-reference-scraper.md
- **Developed by:** [lulz bot](https://apify.com/lulzasaur) (community)
- **Categories:** E-commerce
- **Stats:** 1 total users, 0 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 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.

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

## Basketball Reference Scraper

Scrape NBA and ABA player statistics from [Basketball-Reference.com](https://www.basketball-reference.com). Extract player bios, per-game stats, advanced metrics, and playoff data for all 5,400+ players in the database.

### Features

- **Index Mode** - Quickly scrape all 5,400+ players with name, position, height, weight, birth date, college, and years active
- **Detailed Mode** - Fetch full career stats for each player including per-game averages, advanced metrics, and playoff stats
- **Letter Filter** - Scrape just one letter (a-z) to limit scope
- **Hall of Fame Flag** - Automatically identifies Hall of Fame inductees
- **Structured Data** - Uses `data-stat` attributes and JSON-LD schema.org markup for reliable extraction
- **Rate-Limit Safe** - Built-in 3-second delays between requests to respect Cloudflare limits

### Scrape Modes

#### Index Mode (`index`)

Scrapes the player index pages (`/players/a/` through `/players/z/`) for basic biographical data. Fast — only 25 HTTP requests for all letters.

**Output:**
```json
{
  "name": "LeBron James",
  "position": "F",
  "height": "6-9",
  "weight": "250",
  "birthDate": "December 30, 1984",
  "college": "",
  "yearFrom": 2004,
  "yearTo": 2025,
  "yearsActive": "2004-2025",
  "hallOfFame": false,
  "url": "https://www.basketball-reference.com/players/j/jamesle01.html"
}
````

#### Detailed Mode (`detailed`)

After scraping the index, follows each player URL to extract full career stats. Includes per-game averages, advanced metrics, and playoff data. Much slower — one request per player with 3-second delays.

**Output:**

```json
{
  "name": "LeBron James",
  "position": "F",
  "height": "6-9",
  "weight": "250 lbs",
  "birthDate": "December 30, 1984",
  "college": "St. Vincent-St. Mary (OH)",
  "yearsActive": "2004-2025",
  "hallOfFame": false,
  "fullName": "LeBron Raymone James",
  "birthPlace": "Akron, Ohio",
  "shoots": "Right",
  "draft": "Cleveland Cavaliers, 1st round (1st pick, 1st overall), 2003 NBA Draft",
  "careerGames": 1492,
  "careerPPG": 27.1,
  "careerRPG": 7.5,
  "careerAPG": 7.4,
  "careerSPG": 1.5,
  "careerBPG": 0.8,
  "careerFGPct": 0.505,
  "careerFG3Pct": 0.346,
  "careerFTPct": 0.735,
  "careerPER": 27.1,
  "careerWS": 247.3,
  "careerBPM": 8.9,
  "careerVORP": 145.6,
  "perGameStats": [
    {
      "season": "2003-04",
      "age": 19,
      "team": "CLE",
      "league": "NBA",
      "games": 79,
      "minutesPerGame": 39.5,
      "ptsPerGame": 20.9,
      "rebPerGame": 5.5,
      "astPerGame": 5.9,
      "fgPct": 0.417,
      "fg3Pct": 0.29
    }
  ],
  "advancedStats": [
    {
      "season": "2003-04",
      "per": 18.3,
      "ws": 5.1,
      "bpm": 3.0,
      "vorp": 4.5
    }
  ],
  "playoffPerGameStats": [
    {
      "season": "2005-06",
      "team": "CLE",
      "games": 13,
      "ptsPerGame": 30.8,
      "rebPerGame": 8.1,
      "astPerGame": 5.8
    }
  ],
  "url": "https://www.basketball-reference.com/players/j/jamesle01.html"
}
```

### Input Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `scrapeType` | select | `index` | `index` for bios only, `detailed` for full career stats |
| `letter` | text | (empty) | Single letter a-z to filter by last name initial |
| `maxResults` | integer | 500 | Maximum number of players to return (1-10,000) |
| `proxyConfiguration` | object | Residential | Proxy settings for avoiding rate limits |

### Per-Game Stats Extracted

Games (G), Games Started (GS), Minutes (MPG), Field Goals (FG, FGA, FG%), 3-Pointers (3P, 3PA, 3P%), 2-Pointers (2P, 2PA, 2P%), Effective FG%, Free Throws (FT, FTA, FT%), Offensive Rebounds (ORB), Defensive Rebounds (DRB), Total Rebounds (TRB), Assists (AST), Steals (STL), Blocks (BLK), Turnovers (TOV), Personal Fouls (PF), Points (PTS)

### Advanced Stats Extracted

Player Efficiency Rating (PER), True Shooting % (TS%), 3-Point Attempt Rate, Free Throw Rate, Offensive/Defensive/Total Rebound %, Assist %, Steal %, Block %, Turnover %, Usage %, Offensive/Defensive Win Shares (OWS, DWS, WS), Win Shares per 48 (WS/48), Offensive/Defensive Box Plus-Minus (OBPM, DBPM, BPM), Value Over Replacement Player (VORP)

### Example Use Cases

- **Fantasy Basketball** - Get per-game averages for all active players
- **Historical Analysis** - Compare career stats across eras
- **Draft Research** - Analyze player development year-over-year
- **Hall of Fame Prediction** - Use advanced metrics to project HOF candidates
- **College Pipeline** - Find which colleges produce the most NBA players

### Proxy Configuration

Basketball-Reference uses Cloudflare and may rate-limit at ~20 requests per minute. The scraper has built-in 3-second delays between requests. Residential proxies are recommended for detailed mode runs with many players.

### Technical Notes

- Uses `got-scraping` + `cheerio` for fast HTML parsing (no browser needed)
- Extracts data from `data-stat` attributes on table cells for reliable field mapping
- Parses JSON-LD `schema.org/Person` data for biographical information
- Handles HTML comments (Basketball-Reference hides some stat tables inside comments)
- Rate-limited to ~20 req/min with 3-second delays between requests
- Pay-per-event charging: billed per result returned

# Actor input Schema

## `scrapeType` (type: `string`):

Index mode: scrapes player index pages for name, position, height, weight, college, years active. Detailed mode: also fetches each player's full career stats (per-game, advanced, playoffs).

## `letter` (type: `string`):

Optional: scrape only players whose last name starts with this letter (a-z). Leave empty to scrape all letters.

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

Maximum number of players to return. For index mode, limits total players. For detailed mode, limits how many players get their full stats fetched.

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

Proxy settings. Recommended for large-scale runs to avoid rate limiting by Basketball-Reference (Cloudflare).

## Actor input object example

```json
{
  "scrapeType": "index",
  "maxResults": 500,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# 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 = {
    "letter": ""
};

// Run the Actor and wait for it to finish
const run = await client.actor("lulzasaur/basketball-reference-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 = { "letter": "" }

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

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Basketball Reference Scraper - NBA Player Stats",
        "description": "Scrape Basketball-Reference.com for NBA/ABA player stats. Index mode gets 5,400+ players with bio data. Detailed mode adds full career per-game stats, advanced stats, and playoff stats.",
        "version": "1.0",
        "x-build-id": "5MKS1hkh4YbeqysTd"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/lulzasaur~basketball-reference-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-lulzasaur-basketball-reference-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/lulzasaur~basketball-reference-scraper/runs": {
            "post": {
                "operationId": "runs-sync-lulzasaur-basketball-reference-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/lulzasaur~basketball-reference-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-lulzasaur-basketball-reference-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",
                "properties": {
                    "scrapeType": {
                        "title": "Scrape Type",
                        "enum": [
                            "index",
                            "detailed"
                        ],
                        "type": "string",
                        "description": "Index mode: scrapes player index pages for name, position, height, weight, college, years active. Detailed mode: also fetches each player's full career stats (per-game, advanced, playoffs).",
                        "default": "index"
                    },
                    "letter": {
                        "title": "Letter Filter",
                        "type": "string",
                        "description": "Optional: scrape only players whose last name starts with this letter (a-z). Leave empty to scrape all letters."
                    },
                    "maxResults": {
                        "title": "Max Results",
                        "minimum": 1,
                        "maximum": 10000,
                        "type": "integer",
                        "description": "Maximum number of players to return. For index mode, limits total players. For detailed mode, limits how many players get their full stats fetched.",
                        "default": 500
                    },
                    "proxyConfiguration": {
                        "title": "Proxy Configuration",
                        "type": "object",
                        "description": "Proxy settings. Recommended for large-scale runs to avoid rate limiting by Basketball-Reference (Cloudflare).",
                        "default": {
                            "useApifyProxy": true,
                            "apifyProxyGroups": [
                                "RESIDENTIAL"
                            ]
                        }
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
