I am trying to get the data about types of beers and locations where they are most popular from this webpage: https://untappd.com/La_Source
I wrote the code:
library(rvest)
library(dplyr)
link = "https://untappd.com/La_Source"
page = read_html(link)
name = page %>% html_nodes(".user") %>% html_text()
place = page %>% html_nodes("a:nth-child(4)") %>% html_text()
user = page %>% html_nodes(".user") %>% html_text()
user_links = page %>% html_nodes(".user") %>%
html_attr("href") %>% paste("https://untappd.com/", ., sep="")
get_city = function(user_link) {
# user_link= 'https://untappd.com/user/Linty'
user_page = read_html(user_link)
user_city = user_page %>% html_nodes(".location") %>%
html_text() %>% paste(collapse = ",")
return(user_city)
}
city = sapply(user_links, FUN = get_city, USE.NAMES = FALSE)
#brewery = page %>% html_nodes("a:nth-child(3)") %>% html_text()
Beer = data.frame(name, place,user,city, stringsAsFactors = FALSE)
write.csv(Beer, "Beer.csv")
which works really nicely and gives me needed data. The issue when I try to get more data by ''pressing load more button '' at the bottom of the page. I am not sure how I can do it in R. Any advices ?