I have this code:
library(rvest)
url <- "http://www.example.com/ranking/unit?pagina=1"
url_html <- read_html(url)
whole_table <- url_html %>%
html_nodes('table') %>%
html_table(fill = TRUE) %>%
.[[1]]
url2 <- "http://www.example.com/ranking/unit?pagina=2"
url_html2 <- read_html(url2)
whole_table2 <- url_html2 %>%
html_nodes('table') %>%
html_table(fill = TRUE) %>%
.[[1]]
I run this code up to a dozen times, changing the URL consecutively, and finally join the different whole_table
into a single dataframe. I wonder if there's a more elegant solution without having to repeat these six lines of code twelve times with different numbering.