Skip to content

Instantly share code, notes, and snippets.

@mrcaseb
Last active September 11, 2023 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcaseb/143a25e975736e1c82faddfc08dbe755 to your computer and use it in GitHub Desktop.
Save mrcaseb/143a25e975736e1c82faddfc08dbe755 to your computer and use it in GitHub Desktop.
Scrape nflmockdraftdatabase consensus board
# Scrape nflmockdraftdatabase consensus board from
# https://www.nflmockdraftdatabase.com
load_nflmockdraftdatabase_consensus_board <- function(year){
cli::cli_progress_step("Loading {.val {year}}. Please be patient, the parser takes a while.")
raw <- glue::glue("https://www.nflmockdraftdatabase.com/big-boards/{year}/consensus-big-board-{year}") |>
rvest::read_html()
mock_list <- raw |>
rvest::html_elements(xpath = "//*[@class='mock-list-item']")
pick_no <- mock_list |>
rvest::html_elements(xpath = "//div[@class='left-container']//div[contains(concat(' ',normalize-space(@class),' '),' pick-number ')]") |>
rvest::html_text()
peak <- mock_list |>
rvest::html_elements(xpath = "//div[@class='peak']//span") |>
rvest::html_text()
player <- mock_list |>
rvest::html_elements(xpath = "//div[contains(concat(' ',normalize-space(@class),' '),' player-name ')]") |>
rvest::html_text()
college_details <- mock_list |>
rvest::html_elements(xpath = "//div[@class='player-details college-details']")|>
rvest::html_text()
position <- college_details |>
stringr::str_split_i("\\|", 1) |>
stringr::str_trim()
college <- college_details |>
stringr::str_split_i("\\|", 2) |>
stringr::str_trim() |>
stringr::str_split_i("#|[:digit:]|--", 1)
projection <- college_details |>
stringr::str_split_i("\\|", 2) |>
stringr::str_trim() |>
stringr::str_split_i("#", 2)
consensus_board <- tibble::tibble(
current_rank = as.integer(pick_no),
player = player,
position = position,
college = college,
projected_pick = as.integer(projection),
highest_rank = as.integer(peak)
)
consensus_board
}
# example 2023
load_nflmockdraftdatabase_consensus_board(2023)
#> ℹ Loading 2023. Please be patient, the parser takes a while.
#> ✔ Loading 2023. Please be patient, the parser takes a while. [21.7s]
#>
#> # A tibble: 546 × 6
#> current_rank player position college projected_pick highest_rank
#> <int> <chr> <chr> <chr> <int> <int>
#> 1 1 Bryce Young QB Alabama 1 1
#> 2 2 C.J. Stroud QB Ohio St… 2 1
#> 3 3 Will Anderson Jr. EDGE Alabama 3 1
#> 4 4 Anthony Richardson QB Florida 4 4
#> 5 5 Jalen Carter DL Georgia 6 1
#> 6 6 Christian Gonzalez CB Oregon 7 4
#> 7 7 Tyree Wilson EDGE Texas T… 5 5
#> 8 8 Devon Witherspoon CB Illinois NA 5
#> 9 9 Will Levis QB Kentucky NA 5
#> 10 10 Peter Skoronski OT Northwe… 9 4
#> # ℹ 536 more rows
# Gist URL https://gist.github.com/mrcaseb/143a25e975736e1c82faddfc08dbe755
# Code image at: ![](https://i.imgur.com/D1OMWho.jpg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment