Scraping Super Bowl winners from ESPN with pandas

The Super Bowl is the NFL’s championship game, played each February. ESPN keeps simple HTML tables of every Super Bowl result, MVP and the all-time touchdown leaders, which makes them a good target for pandas.read_html: no browser automation, no parsing by hand.
The goal here is to load those tables, clean them up, and count how many Super Bowls each stadium has hosted.
Install
Section titled “Install”pip install pandas lxml matplotlibread_html needs an HTML parser (lxml, or beautifulsoup4 plus html5lib). matplotlib isn’t imported directly, but pandas uses it for .plot().
Read the tables
Section titled “Read the tables”import pandas as pd
base_url = "https://www.espn.com/nfl"leaders_df = pd.read_html(f"{base_url}/history/leaders", attrs={"class": "tablehead"})[0]winners_df = pd.read_html(f"{base_url}/superbowl/history/winners", attrs={"class": "tablehead"})[0]mvp_df = pd.read_html(f"{base_url}/superbowl/history/mvps", attrs={"class": "tablehead"})[0]
print(leaders_df.head())print(winners_df.head())print(mvp_df.head())read_html returns a list of every <table> on the page that matches attrs; each of these pages has one tablehead table, so [0] takes it.
0 1 20 Touchdown Leaders Touchdown Leaders Touchdown Leaders1 RK PLAYER TD2 1 Jerry Rice 2083 2 Emmitt Smith 1754 3 LaDainian Tomlinson 162 0 ... 30 Super Bowl Winners and Results ... Super Bowl Winners and Results1 NO. ... RESULT2 I ... Green Bay 35, Kansas City 103 II ... Green Bay 33, Oakland 144 III ... New York Jets 16, Baltimore 7The output shows the problem: ESPN’s tables have a title row and then a header row, and pandas treats both as data. The real column names are in row 1.
Fix the headers
Section titled “Fix the headers”winners_df.to_csv("winners_raw.csv", index=False)
winners_df = winners_df.iloc[1:] # drop the title rowwinners_df.columns = winners_df.iloc[0] # use the header row as column nameswinners_df = winners_df.iloc[1:] # drop the header row from the dataprint(winners_df.columns)
winners_df.to_csv("winners.csv", index=False)print(winners_df["SITE"].unique())Index(['NO.', 'DATE', 'SITE', 'RESULT'], dtype='object', name=1)['Los Angeles Memorial Coliseum' 'Orange Bowl (Miami)' 'Tulane Stadium (New Orleans)' 'Rice Stadium (Houston)' 'Rose Bowl (Pasadena, Calif.)' 'Superdome (New Orleans)' ... 'Hard Rock Stadium (Miami)' 'SoFi Stadium (Inglewood, Calif.)']Count games per stadium
Section titled “Count games per stadium”Each site includes the city in parentheses. Strip it so the stadium name alone is the grouping key, then count and plot:
sites = winners_df.copy()sites["SITE"] = sites["SITE"].str.replace(r"\s*\(.*\)", "", regex=True).str.strip()
counts = sites.groupby("SITE").size().sort_values()ax = counts.plot(kind="barh", figsize=(10, 12))fig = ax.get_figure()fig.tight_layout()fig.savefig("winners.png")Pass regex=True explicitly. Since pandas 2.0, Series.str.replace treats the pattern as a literal string by default, so without it the parentheses are never removed and nothing is grouped.

Gotchas
Section titled “Gotchas”- Renamed stadiums count separately. The Superdome appears as “Superdome”, “Mercedes-Benz Superdome” and “Caesars Superdome”; Miami’s stadium has had five names (Joe Robbie, Pro Player, Dolphin, Sun Life, Hard Rock). For an accurate count per venue, map those names to one key before grouping.
- Stripping the city has a side effect. “Tampa (Fla.) Stadium” becomes “Tampa Stadium”, which happens to be correct, but check the unique values after any regex clean-up.
- The page layout can change. If ESPN drops the
tableheadclass or the title row,read_htmlwill raiseValueError: No tables foundor the header fix will pick the wrong row. Printhead()before trusting the columns.
References
Section titled “References”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)