How to pull stats directly from NBA.com/stats?

Home for all your discussion of basketball statistical analysis.
DefVanGundy
Posts: 3
Joined: Mon Nov 18, 2013 5:59 pm

How to pull stats directly from NBA.com/stats?

Post 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?
Jacob Frankel
Posts: 35
Joined: Mon Apr 08, 2013 6:45 am

Re: How to pull stats directly from NBA.com/stats?

Post by Jacob Frankel »

Nope. Copy/paste away.
DefVanGundy
Posts: 3
Joined: Mon Nov 18, 2013 5:59 pm

Re: How to pull stats directly from NBA.com/stats?

Post 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?
boooeee
Posts: 88
Joined: Sun Jan 22, 2012 5:32 am
Contact:

Re: How to pull stats directly from NBA.com/stats?

Post 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.
DefVanGundy
Posts: 3
Joined: Mon Nov 18, 2013 5:59 pm

Re: How to pull stats directly from NBA.com/stats?

Post by DefVanGundy »

Very cool thank you. How do you access the JSON feed for future reference? Thanks again!
boooeee
Posts: 88
Joined: Sun Jan 22, 2012 5:32 am
Contact:

Re: How to pull stats directly from NBA.com/stats?

Post 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.
madstork
Posts: 1
Joined: Wed Nov 20, 2013 1:08 am

Re: How to pull stats directly from NBA.com/stats?

Post 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.
geodeph
Posts: 5
Joined: Sat Jan 18, 2014 4:41 am

Re: How to pull stats directly from NBA.com/stats?

Post 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.
bport
Posts: 5
Joined: Thu Nov 28, 2013 4:18 am

Re: How to pull stats directly from NBA.com/stats?

Post 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
geodeph
Posts: 5
Joined: Sat Jan 18, 2014 4:41 am

Re: How to pull stats directly from NBA.com/stats?

Post 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.
bport
Posts: 5
Joined: Thu Nov 28, 2013 4:18 am

Re: How to pull stats directly from NBA.com/stats?

Post by bport »

Just change the team id and game id to get the games you want.

http://stats.nba.com/stats/shotchartdet ... Shots=true
siedemnastka
Posts: 18
Joined: Sun Nov 24, 2013 7:35 pm
Contact:

Re: How to pull stats directly from NBA.com/stats?

Post 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.
bport
Posts: 5
Joined: Thu Nov 28, 2013 4:18 am

Re: How to pull stats directly from NBA.com/stats?

Post 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.
kohanz
Posts: 34
Joined: Fri Jan 04, 2013 6:58 pm
Contact:

Re: How to pull stats directly from NBA.com/stats?

Post 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.
nileriver
Posts: 63
Joined: Thu Jul 18, 2013 3:24 pm
Location: Vancouver, WA

Re: How to pull stats directly from NBA.com/stats?

Post 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?
Post Reply