How to pull stats directly from NBA.com/stats?
-
- Posts: 3
- Joined: Mon Nov 18, 2013 5:59 pm
How to pull stats directly from NBA.com/stats?
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?
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?
-
- Posts: 35
- Joined: Mon Apr 08, 2013 6:45 am
-
- Posts: 3
- Joined: Mon Nov 18, 2013 5:59 pm
Re: How to pull stats directly from NBA.com/stats?
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?
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.
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.
-
- Posts: 3
- Joined: Mon Nov 18, 2013 5:59 pm
Re: How to pull stats directly from NBA.com/stats?
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?
It's a trick I just recently learned, and it's hit or miss.DefVanGundy wrote:Very cool thank you. How do you access the JSON feed for future reference? Thanks again!
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?
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?
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?
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
http://stats.nba.com/stats/boxscore?Gam ... EndRange=0
Re: How to pull stats directly from NBA.com/stats?
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?
Just change the team id and game id to get the games you want.
http://stats.nba.com/stats/shotchartdet ... Shots=true
http://stats.nba.com/stats/shotchartdet ... Shots=true
-
- Posts: 18
- Joined: Sun Nov 24, 2013 7:35 pm
- Contact:
Re: How to pull stats directly from NBA.com/stats?
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.
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?
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.
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?
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.
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?
Can you provide a link to that JSON feed?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.