Functions to scrape olympic data from olympic.com

get_sports(game)

get_single_event(url)

get_events(table)

get_single_result(url)

get_results(table)

Arguments

game

used in get_sports();
in the format of tokyo-2020, see the slug column in the built-in data olympic_game.

url

used in get_single_event() and get_single_result();
the URL to the sport/ event page, see examples.

table

used in get_events() and get_results();
the tibble produced by get_sports() and get_events(), see examples.

Value

a tibble of event summary

Examples

# sport table in Tokyo 2020
get_sports(game = "tokyo-2020")
#> # A tibble: 46 × 2
#>    game       sport                
#>    <chr>      <chr>                
#>  1 tokyo-2020 wrestling            
#>  2 tokyo-2020 weightlifting        
#>  3 tokyo-2020 water-polo           
#>  4 tokyo-2020 volleyball           
#>  5 tokyo-2020 triathlon            
#>  6 tokyo-2020 trampoline-gymnastics
#>  7 tokyo-2020 tennis               
#>  8 tokyo-2020 taekwondo            
#>  9 tokyo-2020 table-tennis         
#> 10 tokyo-2020 swimming             
#> # … with 36 more rows

# event table from URL or sport table
get_single_event("https://olympics.com/en/olympic-games/tokyo-2020/results/swimming")
#> # A tibble: 35 × 4
#>    `__typename` slug                          title                       gender
#>    <chr>        <chr>                         <chr>                       <chr> 
#>  1 GameEvent    women-s-50m-freestyle         Women's 50m Freestyle       Women 
#>  2 GameEvent    men-s-200m-freestyle          Men's 200m Freestyle        Men   
#>  3 GameEvent    women-s-200m-butterfly        Women's 200m Butterfly      Women 
#>  4 GameEvent    men-s-200m-butterfly          Men's 200m Butterfly        Men   
#>  5 GameEvent    women-s-100m-breaststroke     Women's 100m Breaststroke   Women 
#>  6 GameEvent    men-s-100m-freestyle          Men's 100m Freestyle        Men   
#>  7 GameEvent    women-s-4-x-100m-medley-relay Women's 4 x 100m Medley Re… Women 
#>  8 GameEvent    mixed-4-x-100m-medley-relay   Mixed 4 x 100m Medley Relay Mixed 
#>  9 GameEvent    women-s-100m-butterfly        Women's 100m Butterfly      Women 
#> 10 GameEvent    women-s-200m-breaststroke     Women's 200m Breaststroke   Women 
#> # … with 25 more rows
get_sports(game = "tokyo-2020") %>% head(1) %>% get_events()
#> # A tibble: 18 × 4
#>    game       sport     event                   gender
#>    <chr>      <chr>     <chr>                   <chr> 
#>  1 tokyo-2020 wrestling women-s-freestyle-76kg  Women 
#>  2 tokyo-2020 wrestling women-s-freestyle-68kg  Women 
#>  3 tokyo-2020 wrestling women-s-freestyle-62kg  Women 
#>  4 tokyo-2020 wrestling women-s-freestyle-57kg  Women 
#>  5 tokyo-2020 wrestling women-s-freestyle-53kg  Women 
#>  6 tokyo-2020 wrestling women-s-freestyle-50kg  Women 
#>  7 tokyo-2020 wrestling men-s-greco-roman-97kg  Men   
#>  8 tokyo-2020 wrestling men-s-greco-roman-87kg  Men   
#>  9 tokyo-2020 wrestling men-s-greco-roman-77kg  Men   
#> 10 tokyo-2020 wrestling men-s-greco-roman-67kg  Men   
#> 11 tokyo-2020 wrestling men-s-greco-roman-60kg  Men   
#> 12 tokyo-2020 wrestling men-s-greco-roman-130kg Men   
#> 13 tokyo-2020 wrestling men-s-freestyle-97kg    Men   
#> 14 tokyo-2020 wrestling men-s-freestyle-86kg    Men   
#> 15 tokyo-2020 wrestling men-s-freestyle-74kg    Men   
#> 16 tokyo-2020 wrestling men-s-freestyle-65kg    Men   
#> 17 tokyo-2020 wrestling men-s-freestyle-57kg    Men   
#> 18 tokyo-2020 wrestling men-s-freestyle-125kg   Men   

# event results from URL or event table
url <- "https://olympics.com/en/olympic-games/tokyo-2020/results/swimming/women-s-800m-freestyle"
get_single_result(url)
#> # A tibble: 8 × 4
#>   rank  team  name                     result 
#>   <chr> <chr> <chr>                    <chr>  
#> 1 G     USA   Katie Ledecky            8:12.57
#> 2 S     AUS   Ariarne Titmus           8:13.83
#> 3 B     ITA   Simona Quadarella        8:18.35
#> 4 4     USA   Katie Grimes             8:19.38
#> 5 5     CHN   Jianjiahe Wang           8:21.93
#> 6 6     AUS   Kiah Melverton           8:22.25
#> 7 7     GER   Sarah Kohler             8:24.56
#> 8 8     ROC   Anastasiia Kirpichnikova 8:26.30
get_sports(game = "tokyo-2020") %>% head(1) %>% get_events() %>% head(1) %>% get_results()
#> # A tibble: 16 × 7
#>    game       sport     event                  rank  team  name           result
#>    <chr>      <chr>     <chr>                  <chr> <chr> <chr>          <chr> 
#>  1 tokyo-2020 wrestling women-s-freestyle-76kg G     GER   Aline Focken   12    
#>  2 tokyo-2020 wrestling women-s-freestyle-76kg S     USA   Adeline Maria… 12    
#>  3 tokyo-2020 wrestling women-s-freestyle-76kg B     TUR   Yasemin Adar   14    
#>  4 tokyo-2020 wrestling women-s-freestyle-76kg B     CHN   Qian Zhou      12    
#>  5 tokyo-2020 wrestling women-s-freestyle-76kg =5    KGZ   Aiperi Medet … 8     
#>  6 tokyo-2020 wrestling women-s-freestyle-76kg =5    JPN   Hiroe Minagawa 7     
#>  7 tokyo-2020 wrestling women-s-freestyle-76kg 7     ROC   Natalia Vorob… 3     
#>  8 tokyo-2020 wrestling women-s-freestyle-76kg 8     EST   Epp Mae        3     
#>  9 tokyo-2020 wrestling women-s-freestyle-76kg 9     BLR   Vasilisa Marz… 2     
#> 10 tokyo-2020 wrestling women-s-freestyle-76kg 10    EGY   Samar Amer Ib… 1     
#> 11 tokyo-2020 wrestling women-s-freestyle-76kg 11    CAN   Erica Elizabe… 1     
#> 12 tokyo-2020 wrestling women-s-freestyle-76kg 12    UKR   Alla Belinska  1     
#> 13 tokyo-2020 wrestling women-s-freestyle-76kg 13    KAZ   Elmira Syzdyk… 1     
#> 14 tokyo-2020 wrestling women-s-freestyle-76kg 14    BRA   Aline Da Silv… 0     
#> 15 tokyo-2020 wrestling women-s-freestyle-76kg 15    MGL   Burmaa Ochirb… 0     
#> 16 tokyo-2020 wrestling women-s-freestyle-76kg 16    TUN   Zaineb Sghaier 0