Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelhabr committed Jan 17, 2024
1 parent 87f0f47 commit 23aa57c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 4 additions & 6 deletions R/chromote-fbref.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ worldfootballr_html_player_table <- function(session) {
stopifnot(identical(class(session), c("WorldfootballRDynamicPage", "R6")))

## find element "above" commented out table
node_id1 <- session$find_nodes("#stats_shooting_sh")
## find element "below" commented out table
node_id2 <- session$find_nodes("#stats_shooting_control")
## find commented out element in-between
node_id <- round((node_id1 + node_id2) / 2)
node_id0 <- session$find_nodes("#stats_shooting_sh")
## skip 1 for the div "placeholder"
node_id <- node_id0 + 2L

elements <- session$call_node_method(node_id, ".textContent")[['result']][['value']]
elements <- session$call_node_method(node_id, ".textContent")[["result"]][["value"]]
n_elements <- length(elements)
if (n_elements != 1) {
warning(sprintf("Did not find the expected number of tables on the page (3). Found %s.", n_elements))
Expand Down
4 changes: 3 additions & 1 deletion R/fb_league_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@
.frequency = "once",
.frequency_id = "fb_league_stats-player"
)

session <- worldfootballr_chromote_session(url)
player_table <- worldfootballr_html_player_table(session)
session$session$close(wait_ = FALSE)

if (is.null(player_table)) {
return(tibble::tibble())
}

player_table_elements <- xml2::xml_children(xml2::xml_children(player_table))
parsed_player_table <- rvest::html_table(player_table_elements)
renamed_player_table <- worldfootballR:::.rename_fb_cols(parsed_player_table[[1]])
renamed_table <- renamed_player_table[renamed_player_table$Rk != "Rk", ]
renamed_player_table <- renamed_player_table[renamed_player_table$Rk != "Rk", ]
renamed_player_table <- worldfootballR:::.add_player_href(
renamed_player_table,
parent_element = player_table_elements,
Expand Down

0 comments on commit 23aa57c

Please sign in to comment.