Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Last active June 13, 2017 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlehtoma/6fee0bfac0d4d1db3026cc0d291a4202 to your computer and use it in GitHub Desktop.
Save jlehtoma/6fee0bfac0d4d1db3026cc0d291a4202 to your computer and use it in GitHub Desktop.
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