Skip to content

DebanilBora/NBA-Stats-Scraper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€ NBA Stats Scraper (2020–2024)

A Python script that scrapes NBA player statistics (per game, totals, advanced) from Basketball Reference using Playwright + BeautifulSoup + Pandas and saves them into a single CSV file.

πŸš€ Features

πŸ“Š Scrapes per game, totals, and advanced stats

πŸ“… Covers multiple seasons (2020–2024)

πŸ”„ Retry mechanism with delays to handle failed requests

⏳ Progress bar with tqdm for tracking scraping progress

πŸ–₯ Headless Chromium browser automation with Playwright

πŸ’Ύ Saves results to nba_stats.csv

πŸ›  Tech Stack

Python 3

Libraries:

playwright – headless browser automation

beautifulsoup4 – parse HTML & comments (hidden tables)

pandas – tabular data processing & CSV export

tqdm – progress bar

io.StringIO, time.sleep – retries & parsing support

βš™οΈ Setup & Installation 1️⃣ Clone the repository git clone https://github.com/DebanilBora/NBA-Stats-Scraper.git cd nba-stats-scraper

2️⃣ Create & activate a virtual environment python -m venv .venv source .venv/bin/activate # Linux/Mac .venv\Scripts\activate # Windows

3️⃣ Install dependencies pip install -r requirements.txt

4️⃣ Install Playwright browsers playwright install

▢️ Usage

Run the script:

python app.py

βœ… Opens Chromium in headless mode

βœ… Scrapes NBA player stats for 2020–2024 seasons

βœ… Extracts per game, totals, advanced stats

βœ… Saves final dataset into nba_stats.csv

πŸ“‚ Example Output (CSV) Player Team G PTS TRB AST Season StatType LeBron James LAL 67 25.3 7.8 10.2 2020 per_game Giannis Ant. MIL 63 28.1 11.0 5.9 2020 advanced 🏷 Tags

#Python #WebScraping #NBA #Basketball #DataScience #Playwright #BeautifulSoup #Pandas

About

Python scraper for NBA player stats (per game, totals, advanced) with Playwright and pandas

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages