The RankingTable class provides access to league standings for the top 5 European football leagues. It enables scraping current and historical rankings, with support for multiple export formats including CSV, JSON, and PDF.
The module automatically handles European qualification spots and relegation zones in PDF exports, with color-coded visual indicators.
from premier_league import RankingTable# Get current Premier League standingspl = RankingTable(league="Premier League")standings = pl.get_ranking_list()# Display the tablefor row in standings: print(row)
from premier_league import RankingTable# Initialize for current Premier League seasonpl = RankingTable(league="Premier League")# Export to all formatspl.get_ranking_csv("premier_league_standings", header="PL Standings")pl.get_ranking_json("premier_league_standings", header="standings")pl.get_ranking_pdf("premier_league_standings", dir="reports")print("Exported to CSV, JSON, and PDF!")
# Compare title race across different seasonsseasons = ["2018-2019", "2019-2020", "2020-2021"]for season in seasons: ranking = RankingTable( league="Premier League", target_season=season ) standings = ranking.get_ranking_list() # Get top 3 teams top_3 = standings[1:4] print(f"\n{season} Top 3:") for pos, team, *stats in top_3: points = stats[-1] print(f" {pos}. {team} - {points} pts")
ranking = RankingTable(league="Premier League")standings = ranking.get_ranking_list()# Get teams in European spots (top 7)european_teams = standings[1:8]print("Teams qualifying for Europe:")for row in european_teams: print(f"{row[0]}. {row[1]} - {row[-1]} pts")# Get teams in relegation zone (bottom 3)relegation_teams = standings[-3:]print("\nTeams in relegation zone:")for row in relegation_teams: print(f"{row[0]}. {row[1]} - {row[-1]} pts")
from premier_league import RankingTabletry: # Invalid season format ranking = RankingTable( league="Premier League", target_season="2023" # Should be "2023-2024" )except Exception as e: print(f"Error: {e}")try: # Season before league existed ranking = RankingTable( league="Bundesliga", target_season="1950-1951" # Bundesliga started in 1963 )except Exception as e: print(f"Error: {e}")
Use cache=True (default) to significantly speed up repeated requests for the same season data.
The module automatically handles qualification/relegation markers like “(R)”, “(C)” in the scraped data, providing clean team names in the output.