0

I'm trying scrape this url and store onto a dataframe, however I can't seem to be able to parse this? I tried several other post but so far it as failed.

tryCatch(
  {
    json_data <- read_html(glue ( "https://coinmarketcap.com/historical/20210917" )) %>%
      html_node("#__NEXT_DATA__") %>% 
      html_text() %>% 
      fromJSON()
  },  error=function(e){}
  
) -> json_data


fromJSON(json_data)  %>% as.data.frame #failed

fromJSON(json_data$props)  %>% as.data.frame #failed
fromJSON(json_data$props)  %>% as.data.frame #failed

edit: I think I found the nested text I need but the json structure looks really messed up?

> str ( json_data$props$initialState )
 chr "{\"app\":{\"locale\":\"en-US\",\"theme\":\"DAY\",\"lang\":\"en\",\"country\":\"\",\"currency\":{\"id\":2781,\"n"| __truncated__
> 

Converting nested JSON to data frame Converting nested JSON file to R dataframe Converting a nested JSON to transformed dataframe in R Json read and convert to dataframe

3
  • 1
    That data is not flat, so it is not easily converted to a simple frame. I don't know the context or content of the different columns. Commented Sep 10, 2022 at 19:07
  • 1
    You may need to go through field by field (e.g., props$initialI18nStore, props$pageProps) and determine what it should look like in data.frame form. Once you know how each should look, write a function that takes it and munges each attribute individually and combines into a single frame in the end. Commented Sep 10, 2022 at 19:09
  • This is one huge mess of the data with multiple lists embedded in lists and some additional JSON mixed it. It is best to have a strategy of exactly what data is important and what can be skipped before trying to decode this. Commented Sep 10, 2022 at 19:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.