I have reviewed several answers to similar questions on SO related to this similar topic but neither seem to work for me.
(loop across multiple urls in r with rvest)
(Harvest (rvest) multiple HTML pages from a list of urls)
I have a list of URLs and I wish to grab the table from each and append it to a master dataframe.
## get all urls into one list
page<- (0:2)
urls <- list()
for (i in 1:length(page)) {
url<- paste0("https://www.mlssoccer.com/stats/season?page=",page[i])
urls[[i]] <- url
}
### loop over the urls and get the table from each page
table<- data.frame()
for (j in urls) {
tbl<- urls[j] %>%
read_html() %>%
html_node("table") %>%
html_table()
table[[j]] <- tbl
}
The first section works as expect and gets the list of urls I want to scrape. I get the following error:
Error in UseMethod("read_xml") :
no applicable method for 'read_xml' applied to an object of class "list"
Any suggestions on how to get correct for this error and get the 3 tables looped into a single DF? I appreciate any tips or pointers.