Instantly share code, notes, and snippets.

Embed
What would you like to do?
scraping data from timeanddate.com
library(rvest)
library(dplyr)
main_page <- read_html('https://www.timeanddate.com/holidays/')
all_countries <- main_page %>%
html_nodes(xpath = '//div[@class="row"]//li//a') %>%
html_attr(name = 'href')
holidays <- NULL
pb <- progress_estimated(length(all_countries))
for(country in all_countries){
url <- sprintf('https://www.timeanddate.com/%s', country)
tmp <- read_html(url) %>%
html_table() %>% .[[1]] %>%
mutate(country=country)
holidays[[country]] <- tmp
pb$tick()$print()
}
holidays <- do.call(bind_rows, holidays)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment