本文介绍了无法从URL NBA统计信息中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从stats.nba.com端点获取JSON数据时遇到问题.例如,此网址 http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2016-17&SeasonType=Regular+Season&teamid=1610612761 在我的浏览器中工作正常,但是当我尝试阅读时放入R,我收到错误消息.

I'm having an issue fetching JSON data from the stats.nba.com endpoints. For example, this url http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2016-17&SeasonType=Regular+Season&teamid=1610612761 works fine in my browser, but when I try to read it into R, I receive errors.

jsonlite::fromJSONRJSONIO::fromJSONRCurl::getURLHTTR::get都永远挂起,直到我杀死它们.

jsonlite::fromJSON, RJSONIO::fromJSON, RCurl::getURL, HTTR::get all hang forever until I kill them.

rjson::fromJSON给我一个错误意外字符'h'"

rjson::fromJSON gives me an error "unexpected character 'h'"

我不确定是否存在拒绝程序访问的方法,以及如何解决该问题.

I'm not sure if there is something denying programmatic access, and how I would get around that.

R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit) 
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

`

推荐答案

在尝试处理文件之前,请先下载文件:

Try downloading the file first before trying to process it:

library(curl)
library(jsonlite)

curl_download("http://stats.nba.com/stats/teamgamelog?LeagueID=00&Season=2016-17&SeasonType=Regular+Season&teamid=1610612761", "nba.json")
jsonlist<-fromJSON( "nba.json")
df<-as.data.frame(jsonlist$resultSets$rowSet)
names(df)<-jsonlist$resultSets$headers[[1]]
parameters<-jsonlist$parameters

这篇关于无法从URL NBA统计信息中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:43