Question

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

Was it helpful?

Solution

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]])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top