I tried id 123, and the response structure doesn't seem to be complex:
library(jsonlite)
library(httr)
#convert response into string
my_url <- "http://smarkets.herokuapp.com/bets/123"
response <- GET(my_url)
text <- content(response,as = "text")
# string to list
my_list <- fromJSON(text)
#list to dataframe
mydf <- data.frame(t(sapply(my_list,c)))
Sample result:
> mydf
id user_id amount percentage_odds timestamp result
1 123 421 5.729698 16 2018-06-12T15:49:13.245956399Z FALSE
Make a loop to get all info:
library(jsonlite)
library(httr)
library(glue)
#convert response into string
loop_items <- 1:1000
all_df <- data.frame()
for( i in 1 : 1000){
ua <- user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36")
my_url <- glue("http://smarkets.herokuapp.com/bets/{i}",
i = i)
response <- GET(my_url,ua)
text <- content(response,as = "text")
# string to list
my_list <- fromJSON(text)
#list to dataframe
mydf <- data.frame(t(sapply(my_list,c)))
all_df <- rbind(all_df,mydf)
#sleep 1 second
Sys.sleep(1)
cat(i," completed\n")
}