Page 1 of 2
How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 6:04 pm
by DefVanGundy
Hey guys,
Looking to learn R and figured I'd use some NBA data stuff to break it in. I wanted to pull stats from the NBA Stats page which is more comprehensive than I ever thought it'd be. However I can't export the pages to a CSV or similar file in order to work with it. I can extract it to an image but can I work with that?
Here's an example page I'm referring to:
http://stats.nba.com/teamLineups.html?TeamID=1610612752
is there a way to export this data?
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 6:34 pm
by Jacob Frankel
Nope. Copy/paste away.
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 6:38 pm
by DefVanGundy
Do any other resources have this much information available? I'll pay if I need to...does Synergy have this type of stuff available?
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 7:20 pm
by boooeee
Looks like there is an underying json feed you can access:
http://stats.nba.com/stats/teamdashline ... e=&GameID=
You can use the RJSONIO package in R to convert the JSON feed into a nested list. Then code away.
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 7:25 pm
by DefVanGundy
Very cool thank you. How do you access the JSON feed for future reference? Thanks again!
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Nov 18, 2013 7:49 pm
by boooeee
DefVanGundy wrote:Very cool thank you. How do you access the JSON feed for future reference? Thanks again!
It's a trick I just recently learned, and it's hit or miss.
In Chrome, load the page that has the data you want and then open up developer tools and click on the "Network" heading. You may have to refresh the page after you do that.
After you hit refresh, you'll get a huge list of files that the website is accessing in order to populate the page. Sort by "type" and look for files that have xml or json in the name (e.g. "application/json"). Then it's trial and error to see if one of those files has the data you're looking for.
Re: How to pull stats directly from NBA.com/stats?
Posted: Wed Nov 20, 2013 1:11 am
by madstork
If you're talking about heavy duty copy pasting you need to learn web scraping. You can program scrapers in python (not terribly hard to learn), or get someone to do it for you.
Re: How to pull stats directly from NBA.com/stats?
Posted: Sat Jan 18, 2014 8:59 pm
by geodeph
How about bulk extraction of boxscores? Im trying to extract the boxscores individually but there are no json or xml files whatsoever. Looks like they are coded somewhere but cannot find them. Btw newbie to web but proficient in R.
Re: How to pull stats directly from NBA.com/stats?
Posted: Sat Jan 18, 2014 10:03 pm
by bport
Here is the url for getting a boxscore in json. Just change the game id to get whatever game you want.
http://stats.nba.com/stats/boxscore?Gam ... EndRange=0
Re: How to pull stats directly from NBA.com/stats?
Posted: Sun Jan 19, 2014 1:21 am
by geodeph
Thanks. I tried this and it worked really well. I was wondering how you were able to extract this so that I can replicate in other stas pages. I am also trying to extract spatial data from stats.nba.com per game.
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Jan 20, 2014 10:53 pm
by bport
Just change the team id and game id to get the games you want.
http://stats.nba.com/stats/shotchartdet ... Shots=true
Re: How to pull stats directly from NBA.com/stats?
Posted: Tue Jan 21, 2014 1:32 pm
by siedemnastka
wondering why do guys at stats.nba.com let glitches like this slip through:
http://stats.nba.com/gameDetail.html?Ga ... 1#boxscore
Boston's players' minutes total is 225:21 and there's no mention of Justin Reed who played 15 minutes in this game. It's not like you can't find his name in the play by play.
It seems to be a very common issue for older box scores (probably 04/05 and earlier). My guess is that it should be really easy to fix.
Re: How to pull stats directly from NBA.com/stats?
Posted: Wed Jan 22, 2014 12:34 am
by bport
Yeah there are several like that with players missing not to mention the 1996-97 season having the away team's minutes adding up to over 240 like this:
http://stats.nba.com/gameDetail.html?GameID=0029600001
Makes you wonder if there are other not so obvious glitches.
Re: How to pull stats directly from NBA.com/stats?
Posted: Wed Jan 22, 2014 8:33 pm
by kohanz
You can also find the play by play JSON:
http://stats.nba.com/stats/playbyplay?G ... EndRange=0
Unfortunately NBA.com only uses last names for player references, which can be difficult when dealing with teams with multiple players sharing the same last name. I use CNNSI, which also has a JSON feed, but the PBP includes first names. These include glitches too. Some are very subtle. For example, a substitution where the player name is wrong. Not much to do about that, these events are logged by humans at some point in the chain, so errors are inevitable.
Re: How to pull stats directly from NBA.com/stats?
Posted: Mon Jan 27, 2014 6:33 am
by nileriver
kohanz wrote:You can also find the play by play JSON:
http://stats.nba.com/stats/playbyplay?G ... EndRange=0
Unfortunately NBA.com only uses last names for player references, which can be difficult when dealing with teams with multiple players sharing the same last name. I use CNNSI, which also has a JSON feed, but the PBP includes first names. These include glitches too. Some are very subtle. For example, a substitution where the player name is wrong. Not much to do about that, these events are logged by humans at some point in the chain, so errors are inevitable.
Can you provide a link to that JSON feed?