Skip to content

Instantly share code, notes, and snippets.

@robsalasco
Created August 31, 2017 22:22
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 robsalasco/597de48a680845027c21ff7b88cba44c to your computer and use it in GitHub Desktop.
Save robsalasco/597de48a680845027c21ff7b88cba44c to your computer and use it in GitHub Desktop.
library(rvest)
library(stringr)
html <- read_html("http://www.asof.cl/apps/mapaferias/rm.php")
urls <- html %>% html_nodes("option") %>% html_attr("value") %>% na.omit()
maps <- sapply(urls, function(x) {
read_html(paste0("http://www.asof.cl/apps/mapaferias/",x)) %>%
html_nodes("iframe") %>%
html_attr("src")
}
)
ids <- sapply(maps, function(x) {
str_extract(read_html(x) %>% html_nodes(xpath = '//meta[@itemprop="url"]') %>% html_attr('content'), "[-_0-9A-Za-z]+$")
}
)
for (mid in ids) {
download.file(paste0("https://www.google.com/maps/d/u/0/kml?mid=",mid,"&forcekml=1"),paste0("kml/",mid))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment