The PlayerSeasonLeaders class provides access to top player statistics for goals and assists across the top 5 European football leagues. It enables retrieving, analyzing, and exporting season-leading player data in multiple formats.
This module scrapes historical and current season data for top scorers and assist leaders, supporting seasons dating back to the 1980s-1990s depending on the league.
from premier_league import PlayerSeasonLeaders# Get current season's top scorersscorers = PlayerSeasonLeaders(stat_type="G", league="Premier League")top_players = scorers.get_top_stats_list(limit=10)# Display top 10 scorersfor player in top_players[1:]: # Skip header row name, country, club, goals, breakdown = player print(f"{name} ({club}): {goals} goals")
Retrieve the processed list of top players and their statistics.
scorers = PlayerSeasonLeaders( stat_type="G", league="Serie A", target_season="2023-2024")# Get top 20 scorerstop_20 = scorers.get_top_stats_list(limit=20)# First row is headersheaders = top_20[0]print(headers) # ['Name', 'Country', 'Club', 'Goals', 'In Play Goals+Penalty']# Subsequent rows are player datafor player in top_20[1:]: name, country, club, goals, breakdown = player print(f"{name}: {goals} goals for {club}")
from premier_league import PlayerSeasonLeaders# Get all top scorersscorers = PlayerSeasonLeaders( stat_type="G", league="Premier League", target_season="2023-2024")all_scorers = scorers.get_top_stats_list() # No limit = all players# Filter players from a specific clubclub_filter = "Arsenal"arsenal_scorers = [ player for player in all_scorers[1:] if club_filter in player[2]]print(f"{club_filter} Goal Scorers:")for player in arsenal_scorers: print(f" {player[0]}: {player[3]} goals")# Find players with 20+ goalshigh_scorers = [ player for player in all_scorers[1:] if int(player[3]) >= 20]print(f"\nPlayers with 20+ goals: {len(high_scorers)}")for player in high_scorers: print(f" {player[0]} ({player[2]}): {player[3]} goals")
from premier_league import PlayerSeasonLeaders# Get top scorersscorers = PlayerSeasonLeaders( stat_type="G", league="Serie A", target_season="2023-2024")top_players = scorers.get_top_stats_list(limit=30)# Identify players on loan (club field contains comma)loaned_players = [ player for player in top_players[1:] if ',' in player[2]]if loaned_players: print("Top scorers currently on loan:") for player in loaned_players: print(f" {player[0]}: {player[2]} - {player[3]} goals")
from premier_league import PlayerSeasonLeaderstry: # Attempting to access data before availability old_data = PlayerSeasonLeaders( stat_type="A", league="Serie A", target_season="2000-2001" # Before 2010-2011 limit )except Exception as e: print(f"Error: Season not available - {e}")try: # Invalid stat type invalid = PlayerSeasonLeaders( stat_type="X", # Must be 'G' or 'A' league="Premier League" )except Exception as e: print(f"Error: Invalid stat type - {e}")
Use cache=True to cache scraped data and significantly improve performance when accessing the same season multiple times.
The module automatically handles multi-word club names and special characters in player names and nationalities.