Created
August 31, 2017 22:22
-
-
Save robsalasco/597de48a680845027c21ff7b88cba44c 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) | |
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