I have just started with web scraping in R and I have trouble finding out how to scrape specific information from a website with several pages without having to do run the code for each individual url. So far I have managed to do it for the first page using this example: https://towardsdatascience.com/tidy-web-scraping-in-r-tutorial-and-resources-ac9f72b4fe47.
I have also managed to generate the urls based on pagenumber with this code:
list_of_pages <- str_c(url, '?page=', 1:32)
The problem is to integrate this and use the generated urls to get the information I need using one function and store it in a dataframe. This is the code I have for scraping the information:
hot100page <- "https://www.billboard.com/charts/hot-100"
hot100 <- read_html(hot100page)
rank <- hot100 %>%
rvest::html_nodes('body') %>%
xml2::xml_find_all("//span[contains(@class, 'chart-element__rank__number')]") %>%
rvest::html_text()
This is an example of the sturture of the website i plan to use the function for: https://www.amazon.com/s?k=statistics&ref=nb_sb_noss_2.