문제

I'm trying to download NBA player information from Numberfire and then put that information into a data frame. However I seem to be running into a few issues

The following snippet downloads the information just fine

require(RCurl)
require(stringr)
require(rjson)

#download data from numberfire
nf <- "https://www.numberfire.com/nba/fantasy/fantasy-basketball-projections"
html <- getURL(nf)

Then there is what I assume to be a JSON data structure

#extract json variable (?)
pat <- "NF_DATA.*}}}"
jsn <- str_extract(html, pat)
jsn <- str_split(jsn, "NF_DATA = ")
parse <- newJSONParser()
parse$addData(jsn)

It seems to add data OK as it doesn't throw any errors, but if there is data in that object I can't tell or seem to get it out!

I'd paste in the jsn variable but it's way over the character limit. Any hints as to where I'm going wrong would be much appreciated

도움이 되었습니까?

해결책

Adding the final line gets a nice list format that you can transform to a data.frame

require(RCurl); require(stringr); require(rjson)

#download data from numberfire
nf <- "https://www.numberfire.com/nba/fantasy/fantasy-basketball-projections"
html <- getURL(nf)

#extract json variable (?)
pat <- "NF_DATA.*}}}"
jsn <- str_extract(html, pat)
jsn <- str_split(jsn, "NF_DATA = ")
fromJSON(jsn[[1]][[2]])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top