# 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
- **Features:** Limited permissions
- **Stats:** 7 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# 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",
  "letter": "",
  "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(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 '{
  "letter": ""
}' |
apify call lulzasaur/basketball-reference-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,lulzasaur/basketball-reference-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/9L03vtIIG7QN9SI0B/builds/5MKS1hkh4YbeqysTd/openapi.json
