Skip to content

Instantly share code, notes, and snippets.

@tonyelhabr
Created January 26, 2024 13:59
Show Gist options
  • Save tonyelhabr/8634e363478853d9acc6c8467795ce5f to your computer and use it in GitHub Desktop.
Save tonyelhabr/8634e363478853d9acc6c8467795ce5f to your computer and use it in GitHub Desktop.
Get Big 5 team logos from FBref
library(rvest)
library(tibble)

url <- 'https://fbref.com/en/comps/Big5/Big-5-European-Leagues-Stats'
page <- read_html(url)

team_elements <- page |> 
  html_elements('table') |> 
  html_elements('td[data-stat="team"]')

logo_urls <- team_elements |> 
  html_elements('img') |> 
  html_attr('src')

team_names <- team_elements |> 
  html_elements('a') |> 
  html_text2()

tibble(
  team_name = team_names,
  logo = logo_urls
)
#> # A tibble: 96 × 2
#>    team_name       logo                                                         
#>    <chr>           <chr>                                                        
#>  1 Leverkusen      https://cdn.ssref.net/req/202301181/tlogo/fb/mini.c7a9f859.p…
#>  2 Inter           https://cdn.ssref.net/req/202301181/tlogo/fb/mini.d609edc0.p…
#>  3 Real Madrid     https://cdn.ssref.net/req/202301181/tlogo/fb/mini.53a2f082.p…
#>  4 Girona          https://cdn.ssref.net/req/202301181/tlogo/fb/mini.9024a00a.p…
#>  5 Juventus        https://cdn.ssref.net/req/202301181/tlogo/fb/mini.e0652b02.p…
#>  6 Bayern Munich   https://cdn.ssref.net/req/202301181/tlogo/fb/mini.054efa67.p…
#>  7 Paris S-G       https://cdn.ssref.net/req/202301181/tlogo/fb/mini.e2d8892c.p…
#>  8 Liverpool       https://cdn.ssref.net/req/202301181/tlogo/fb/mini.822bd0ba.p…
#>  9 Barcelona       https://cdn.ssref.net/req/202301181/tlogo/fb/mini.206d90db.p…
#> 10 Manchester City https://cdn.ssref.net/req/202301181/tlogo/fb/mini.b8fd03ef.p…
#> # ℹ 86 more rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment