seemethere / nba_py

Python client for NBA statistics located at stats.nba.com
BSD 3-Clause "New" or "Revised" License
1.05k stars 255 forks source link

I am missing something with the shotchartlineupdetail #128

Open derek-corcoran-barrios opened 5 years ago

derek-corcoran-barrios commented 5 years ago

Hi, your repository has been a great help to me,I would love to help if possible, I was trying to scrape data from the shotchartlineup detail, and I am sure I am missing something, this is the request I am sending

https://stats.nba.com/stats/shotchartlineupdetail/?CFID=33&CFPARAMS=2018-19&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2018-19&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition=&GROUP_ID=0

I figured it out with the shotchartdetail, but still cannot get it in the shotchartlineupdetail.

This is what I usually do in shotchartdetail

Using R;

library("rvest")
library("tidyverse")

shotURLtotal <- "http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2018-19&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2018-19&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition="

 # import from JSON
Season2019b <- fromJSON(file = shotURLtotal, method="C")
Names <- Season2019b$resultSets[[1]][[2]]
# unlist shot data, save into a data frame
Season2019b <- data.frame(matrix(unlist(Season2019b$resultSets[[1]][[3]]), ncol = 24, byrow = TRUE))
colnames(Season2019b) <- Names

But when I try with shotchartlineup detail

Now I just add the GROUP_ID parameter

 shotURLtotal <- "https://stats.nba.com/stats/shotchartlineupdetail/?CFID=33&CFPARAMS=2018-19&ContextFilter=&ContextMeasure=FGA&DateFrom=10/19/2018&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2018-19&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition=&GROUP_ID=0"
 Season2019c <- fromJSON(file = shotURLtotal, method="C")
 Season2019c$resultSets[[1]][[3]]

 Names <- Season2019c$resultSets[[1]][[2]]

Season2019c <- data.frame(matrix(unlist(Season2019c$resultSets[[1]][[3]]), ncol = 24, byrow = TRUE))

colnames(Season2019c) <- Names