Этот скрипт должен работать, предполагая, что ваши утверждения и разбор API / Web-страницы верны.
Подробности см. В комментариях:
end_date <- Sys.Date()
start_date <- as.Date("2020-01-27", format = "%Y-%m-%d")
the_date <- start_date
#create an empty list
output<-list()
while(the_date <= end_date)
{
#Track which date is being pulled - handy for debugging when script errors
print(the_date)
url <- paste0("https://website.com/api/?action=search_pcrs&e1=eTimes.03&o1=between&v1=",
the_date,
"^",
end_date,
"&e2=eMedications.03&o2=in&v2type=id&v2=14731^14730^14729^3864&col...")
api_get <- GET(url)
api_raw <- rawToChar(api_get$content)
api_tree <- xmlTreeParse(api_raw, useInternalNodes = T)
#Append dataframe to list - item named by date
output[[as.character(the_date)]]<-xmlToDataFrame(api_tree, nodes = getNodeSet(api_tree, "//pcr"))
#slight system pause to prevent attacking the server
Sys.sleep(0.7)
the_date <- the_date + 1
}
#combine all of the dataframes in the output list into one large data frame
alloutput<-do.call(rbind, output)