Last active
August 16, 2023 21:25
-
-
Save matt-dray/9d9ee59583171b5c9c02cbafc4f89149 to your computer and use it in GitHub Desktop.
Using R to extract data out of some HTML code for a leaflet map (needed for a blogdown to Quarto blog conversion for rostrum.blog)
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
x <- readLines("~/Desktop/leaflet-map.txt") | |
popup_html <- stringr::str_split_1(x, "\",\"") | |
lmb_simple <- tibble::tibble( | |
status_id = stringr::str_extract(popup_html, "\\d{19}"), | |
lat = stringr::str_extract(popup_html, "(?<=📍 )5\\d{1}\\.\\d{0,4}(?=, )"), | |
lon = stringr::str_extract(popup_html, "(?<=\\d, )(-)?\\d\\.\\d{0,4}(?=<br>📮)"), | |
osm_url = glue::glue("https://www.openstreetmap.org/#map=17/{lat}/{lon}/"), | |
media_url = stringr::str_extract(popup_html, "(?<=img src=\\')http://pbs\\.twimg\\.com/media/.*\\.jpg(?=\\' width)") | |
) | |
lmb_simple <- lmb_simple[complete.cases(lmb_simple), ] | |
lmb_simple$lat <- as.numeric(lmb_simple$lat) | |
lmb_simple$lon <- as.numeric(lmb_simple$lon) | |
saveRDS(lmb_simple, "~/Desktop/lmb_simple.rds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment