Last active
June 13, 2017 13:44
-
-
Save jlehtoma/6fee0bfac0d4d1db3026cc0d291a4202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
library(stringr) | |
library(tidyverse) | |
base_url <- "http://www.metsakartat.fi/" | |
get_zip <- function(x) { | |
message("Downloading ", x, "...") | |
download.file(x, basename(x), "internal") | |
return(invisible(TRUE)) | |
} | |
# Parse the DOM | |
metsakartat <- xml2::read_html(base_url) | |
# Get al data-zip attribute values | |
data_zips <- metsakartat %>% | |
rvest::html_nodes("*") %>% | |
rvest::html_attr("data-zip") %>% | |
na.omit() %>% | |
purrr::map(stringr::str_split, pattern = ", ") %>% | |
unlist() | |
purrr::map(data_zips, get_zip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment