Overview
ThePlayerSeasonLeaders class provides methods to retrieve, process, and export player statistics (goals or assists) in various formats for the Top 5 European Leagues.
Constructor
PlayerSeasonLeaders
The type of statistic to scrape:
"G": Goals"A": Assists
The specific season to scrape data for (e.g., “2023-2024”). If not provided, the current season is used
The league to scrape data for. Supported leagues:
- “Premier League”
- “La Liga”
- “Serie A”
- “Ligue 1”
- “Bundesliga”
Whether to cache scraped data
Example
Methods
get_top_stats_list
The number of top players to include. If None, returns all available players (up to 100)
A list of lists containing player statistics. The first row contains headers, subsequent rows contain player data
Data Structure
For goals (stat_type="G"):
stat_type="A"):
Example
get_top_stats_csv
The name of the file to save (without extension)
Optional header for the CSV file
The number of top players to include. If None, includes all players
This method doesn’t return a value. It creates a CSV file
Example
get_top_stats_json
The name of the file to save (without extension)
Optional header for the JSON file
The number of top players to include. If None, includes all players
This method doesn’t return a value. It creates a JSON file
Example
get_top_stats_pdf
premier_league[pdf] to be installed.
This method creates a formatted PDF with a title, table of statistics, and styling to enhance readability. The top scorer/assist provider is highlighted in gold.
The name of the file to save (without extension)
The directory path to save the PDF file
This method doesn’t return a value. It creates a PDF file
PDF Features
- Displays top 20 players (header row + 21 data rows)
- Top player highlighted with gold background
- Centered title with league and season information
- Professional table styling with borders and padding
Exceptions
RaisesException if PDF creation fails
Example
find_season_limit
The earliest year with data for the league and stat type
Season Limits by League and Stat Type
Goals (G):- Premier League: 1995
- La Liga: 2008
- Serie A: 2010
- Ligue 1: 2010
- Bundesliga: 1988
- Premier League: 1997
- La Liga: 2008
- Serie A: 2010
- Ligue 1: 2010
- Bundesliga: 1988
Example
Attributes
league
stat_type
season
stat_url
Data Processing
The class automatically:- Cleans raw data: Removes season markers, numbering, and irrelevant text
- Handles multi-word club names: Properly parses club names that contain commas or multiple words
- Structures data: Organizes player information into consistent rows
- Separates goal types: For goals, distinguishes between total goals and the breakdown of in-play vs penalty goals
Dependencies
Optional Dependencies
To use the PDF export functionality, install the package with PDF support:reportlab library required for PDF generation.
Usage Notes
- The limit parameter in
get_top_stats_list()applies to data rows only (header is always included) - Maximum of 100 players can be retrieved (this is typically more than enough as most seasons have fewer top scorers/assists tracked)
- For goals, the data includes both total goals and a breakdown showing in-play goals and penalties
- Club names with special characters or multiple parts are handled automatically