Hello everyone,
Thank you for taking a look at my post. I am in urgent need of some help with a simple web scraping related project I am working on.
My issue is that I have used this exact same code before and it worked well. But for some reason, I am now getting this error: "Error: Argument 'txt' must be a JSON string, URL or file."
This is a large frustration of course. I have two questions
- may you please provide some insight into why I am having this issue.
- Is this the best method of web scraping in R? (the purpose of this web scrape is to extract a large (100's of observations of approx 20 variables) data frame.
I have provided my code below.
'''
library (dplyr)
library(jsonlite)
library(httr)
my_url <- "https://api.nhle.com/stats/rest/en/skater/summary?isAggregate=false&isGame=true&sort=%5B%7B%22property%22:%22points%22,%22direction%22:%22DESC%22%7D,%7B%22property%22:%22goals%22,%22direction%22:%22DESC%22%7D,%7B%22property%22:%22assists%22,%22direction%22:%22DESC%22%7D%5D&start=0&limit=100&factCayenneExp=gamesPlayed%3E=1&cayenneExp=franchiseId%3D21%20and%20gameDate%3C=%222020-03-11%2023%3A59%3A59%22%20and%20gameDate%3E=%222019-10-02%22%20and%20gameTypeId=2"
my_raw_results <- httr::GET(my_url)
data_content <- httr::content(my_raw_results, as = "parsed")
complete_df <- jsonlite::fromJSON(data_content)
complete_df2 <- as.data.frame(complete_df)
'''
Thank you for your help.