R/get_current_url.R

Defines functions get_current_url

Documented in get_current_url

#' Get URL of current XML data set
#' 
#' Extract the url from the static source web page.
#' 
#' @return Returns URL to municipality inventory

get_current_url <- function() {
  
  url_xml_link <- file.path("https://www.bfs.admin.ch", 
                            "bfs/de/home/statistiken/kataloge-datenbanken.assetdetail.dz-b-00.04-hgv-02.html")
  
  hp_object <- read_html(url_xml_link)
  current_url <- html_nodes(hp_object,"a") %>% html_attr("href")
  current_url <- current_url[grep("assets", current_url, perl = FALSE)]
  current_url <- unique(current_url[grep("master", current_url, perl = FALSE)])
  
  if (length(current_url) > 1) {
    stop("error: Link detection failed.")
  }
  
  return(current_url)
}

Try the SMMT package in your browser

Any scripts or data that you put into this service are public.

SMMT documentation built on April 4, 2022, 1:07 a.m.