Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active August 16, 2023 21:25
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 matt-dray/9d9ee59583171b5c9c02cbafc4f89149 to your computer and use it in GitHub Desktop.
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)
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