7.13. Case Study HTML NBA

7.13.1. Code

"""
>>> df
   LeagueID SeasonID      TeamID       TeamCity       TeamName      TeamSlug Conference  ... TotalPoints  OppTotalPoints DiffTotalPoints LeagueGamesBack PlayoffSeeding  ClinchedPostSeason  NEUTRAL
0        00    22024  1610612739      Cleveland      Cavaliers     cavaliers       East  ...        2447            2251             196             0.0           None                   0      0-0
1        00    22024  1610612760  Oklahoma City        Thunder       thunder       West  ...        2164            1961             203             1.5           None                   0      0-0
2        00    22024  1610612738         Boston        Celtics       celtics       East  ...        2302            2101             201             0.5           None                   0      0-0
3        00    22024  1610612745        Houston        Rockets       rockets       West  ...        2287            2117             170             3.0           None                   0      0-0
4        00    22024  1610612753        Orlando          Magic         magic       East  ...        2277            2158             119             3.5           None                   0      0-0
5        00    22024  1610612763        Memphis      Grizzlies     grizzlies       West  ...        2419            2250             169             4.0           None                   0      0-0
6        00    22024  1610612744   Golden State       Warriors      warriors       West  ...        2207            2086             121             4.5           None                   0      0-0
7        00    22024  1610612752       New York         Knicks        knicks       East  ...        2238            2144              94             5.5           None                   0      0-0
8        00    22024  1610612742         Dallas      Mavericks     mavericks       West  ...        2339            2209             130             5.0           None                   0      0-0
9        00    22024  1610612748          Miami           Heat          heat       East  ...        1887            1860              27             6.5           None                   0      1-0
10       00    22024  1610612743         Denver        Nuggets       nuggets       West  ...        2002            1969              33             5.5           None                   0      0-0
11       00    22024  1610612749      Milwaukee          Bucks         bucks       East  ...        2153            2136              17             6.5           None                   0      0-0
12       00    22024  1610612756        Phoenix           Suns          suns       West  ...        2150            2164             -14             5.5           None                   0      0-0
13       00    22024  1610612737        Atlanta          Hawks         hawks       East  ...        2439            2507             -68             7.5           None                   0      0-0
14       00    22024  1610612747    Los Angeles         Lakers        lakers       West  ...        2174            2199             -25             5.5           None                   0      0-0
15       00    22024  1610612754        Indiana         Pacers        pacers       East  ...        2287            2362             -75             8.0           None                   0      0-0
16       00    22024  1610612746             LA       Clippers      clippers       West  ...        2278            2232              46             5.5           None                   0      0-0
17       00    22024  1610612751       Brooklyn           Nets          nets       East  ...        2236            2296             -60             8.0           None                   0      0-0
18       00    22024  1610612759    San Antonio          Spurs         spurs       West  ...        2095            2090               5             6.5           None                   0      0-0
19       00    22024  1610612765        Detroit        Pistons       pistons       East  ...        2416            2457             -41             9.0           None                   0      0-0
20       00    22024  1610612741        Chicago          Bulls         bulls       East  ...        2488            2609            -121             9.5           None                   0      0-0
21       00    22024  1610612750      Minnesota   Timberwolves  timberwolves       West  ...        2112            2096              16             7.5           None                   0      0-0
22       00    22024  1610612758     Sacramento          Kings         kings       West  ...        2274            2267               7             8.0           None                   0      0-0
23       00    22024  1610612766      Charlotte        Hornets       hornets       East  ...        2150            2242             -92            11.0           None                   0      0-0
24       00    22024  1610612757       Portland  Trail Blazers       blazers       West  ...        2121            2272            -151             9.0           None                   0      0-0
25       00    22024  1610612761        Toronto        Raptors       raptors       East  ...        2249            2336             -87            12.0           None                   0      0-0
26       00    22024  1610612755   Philadelphia          76ers        sixers       East  ...        1892            2018            -126            12.0           None                   0      0-0
27       00    22024  1610612762           Utah           Jazz          jazz       West  ...        2063            2252            -189            12.5           None                   0      0-0
28       00    22024  1610612740    New Orleans       Pelicans      pelicans       West  ...        2076            2311            -235            13.0           None                   0      0-0
29       00    22024  1610612764     Washington        Wizards       wizards       East  ...        1946            2216            -270            14.0           None                   0      0-1
<BLANKLINE>
[30 rows x 92 columns]
"""

import pandas as pd
import requests

pd.set_option('display.width', 200)
pd.set_option('display.max_columns', 15)
pd.set_option('display.max_rows', 100)
pd.set_option('display.min_rows', 100)
pd.set_option('display.max_seq_items', 100)


# curl 'https://stats.nba.com/stats/leaguestandingsv3?LeagueID=00&Season=2024-25&SeasonType=Regular%20Season' \
#  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36' \
#  -H 'Origin: https://www.nba.com' \
#  -H 'Referer: https://www.nba.com/'

# DATA = 'https://stats.nba.com/stats/leaguestandingsv3?LeagueID=00&Season=2024-25&SeasonType=Regular%20Season'
DATA = 'https://python3.info/_static/sport-nba.json'

resp = requests.get(DATA, headers={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
    'Origin': 'https://www.nba.com',
    'Referer': 'https://www.nba.com/',
})

data = resp.json()['resultSets'][0]

df = pd.DataFrame(
    columns=data['headers'],
    data=data['rowSet'],
)