Skip to content

Instantly share code, notes, and snippets.

@franTarkenton
Last active May 2, 2024 00:16
Show Gist options
  • Save franTarkenton/55b1df3bad47740b5be303321f84664e to your computer and use it in GitHub Desktop.
Save franTarkenton/55b1df3bad47740b5be303321f84664e to your computer and use it in GitHub Desktop.
Scraping NHL data

Getting started scraping stats from NHL

Docs:

Dependencies

  • python3
  • requests module

Configure Env

create a virtualenv python3 -m venv venv

activate it source venv/bin/activate

install requests python3 -m pip install requests

printing team data

import requests
import os

baseUrl_1 = 'https://api-web.nhle.com/'
baseUrl_2 = 'https://api.nhle.com/'

# get teams

url = os.path.join(baseUrl_2, 'stats/rest/en/team')
response = requests.get(url)
teams = response.json()
#print(teams)

# iterate over teams, printing the name and the code
for team in teams['data']:
    print(f"{team['fullName']} - {team['rawTricode']}")

should output:

Atlanta Thrashers - ATL
Hartford Whalers - HFD
Minnesota North Stars - MNS
Quebec Nordiques - QUE
Winnipeg Jets (1979) - WIN
Colorado Rockies - CLR
Ottawa Senators (1917) - SEN
Hamilton Tigers - HAM
Pittsburgh Pirates - PIR
Philadelphia Quakers - QUA
Detroit Cougars - DCG
Montreal Wanderers - MWN
Quebec Bulldogs - QBD
Montreal Maroons - MMR
New York Americans - NYA
St. Louis Eagles - SLE
Oakland Seals - OAK
Atlanta Flames - AFM
Kansas City Scouts - KCS
Cleveland Barons - CLE
Detroit Falcons - DFL
Brooklyn Americans - BRK
California Golden Seals - CGS
Toronto Arenas - TAN
Toronto St. Patricks - TSP
NHL - NHL
Detroit Red Wings - DET
Boston Bruins - BOS
Winnipeg Jets - WPG
Seattle Kraken - SEA
Pittsburgh Penguins - PIT
Tampa Bay Lightning - TBL
Philadelphia Flyers - PHI
Toronto Maple Leafs - TOR
Carolina Hurricanes - CAR
Arizona Coyotes - ARI
Calgary Flames - CGY
Montréal Canadiens - MTL
Washington Capitals - WSH
Vancouver Canucks - VAN
Colorado Avalanche - COL
Nashville Predators - NSH
Anaheim Ducks - ANA
Vegas Golden Knights - VGK
Dallas Stars - DAL
Phoenix Coyotes - PHX
Chicago Blackhawks - CHI
New York Rangers - NYR
Columbus Blue Jackets - CBJ
Florida Panthers - FLA
Edmonton Oilers - EDM
Minnesota Wild - MIN
St. Louis Blues - STL
Ottawa Senators - OTT
New York Islanders - NYI
Los Angeles Kings - LAK
New Jersey Devils - NJD
To be determined - TBD
XXX - XXX
Buffalo Sabres - BUF
San Jose Sharks - SJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment