Skip to content

Instantly share code, notes, and snippets.

@amoeba
Last active September 4, 2024 00:49
Show Gist options
  • Save amoeba/87e45412095a961dff79195d2915aec5 to your computer and use it in GitHub Desktop.
Save amoeba/87e45412095a961dff79195d2915aec5 to your computer and use it in GitHub Desktop.
library(dplyr)
library(readr)
library(rvest)
library(glue)
years <- 1984:2023
get_one <- function(year) {
url <- glue::glue("https://registration.klondikeroadrelay.com/results?year={year}&leg=Any&gender=Any&name=&team_type=Adult+Running+-+Skagway+Start&division=Any&category=Any&commit=Reload")
doc <- rvest::read_html(url)
results_table <- rvest::html_elements(doc, xpath="//table")
stopifnot(length(results_table)==1)
tbls <- html_table(results_table)
stopifnot(length(tbls)==1)
tbl <- tbls[[1]]
tbl |> mutate(year=year, .before=everything())
}
dfs <- lapply(years, function(y) {
message(y)
result <- get_one(y)
Sys.sleep(1) # be nice
result
})
all_results <- do.call(rbind.data.frame, dfs)
write_csv(all_results, "all-klondike-results.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment