I found Greg Reda's blog post about scraping HTML from nba.com:
http://www.gregreda.com/2015/02/15/web-scraping-finding-the-api/
I tried to work with the code he wrote there:
import requests
import json
url = 'http://stats.nba.com/stats/leaguedashteamshotlocations?Conference=&DateFr' + \
'om=&DateTo=&DistanceRange=By+Zone&Division=&GameScope=&GameSegment=&LastN' + \
'Games=0&LeagueID=00&Location=&MeasureType=Opponent&Month=0&OpponentTeamID' + \
'=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperien' + \
'ce=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2014-15&SeasonSegment=&Seas' + \
'onType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&VsConference=&VsDivision='
response = requests.get(url)
response.raise_for_status()
shots = response.json()['resultSets']['rowSet']
avg_percentage = shots['OPP_FG_PCT']
print(avg_percentage)
But it returns:
Traceback (most recent call last):
File "C:\Python34\nba.py", line 91, in <module>
avg_percentage = shots['OPP_FG_PCT']
TypeError: list indices must be integers, not str
I know only basic Python so I couldn't figure out how to get a list of integers from the data. Can anybody explain?