- In your browser, go the URL where you can find the data that you want. For example,
https://www.fotmob.com/leagues/126/stats/premier-division?season=2024
- Use the browser's "Inspect" feature and "Network" tab to find the right
GET
request. You should be able to tell which request is the right one by looking to see if there is a detailed JSON response in the "Response" tab. - Right click on the request and copy the CURL command.
- Go to
https://curlconverter.com
, copy the CURL command into the "curl command" box at the top of the page with "R > httr2" (or "R > httr") selected. - Copy the R commands from the website into a RStudio and work on parsing out the content that you want. For example
library(httr2)
resp <- # all the stuff from curlconverter
# My parsing code
cont <- resp_body_json(resp)
teams <- cont$stats$teams
In this specific example, you may actually just be ordered in one stat--for example, team goals per match. To extract this, it's easier to identify the data URL in the CURL response, navigate to that URL in a separate browser tab to identify the elements that you'll want, then parse things with code.
library(httr2)
library(dplyr)
library(janitor)
resp_stat <- request('https://data.fotmob.com/stats/126/season/22578/goals_team_match.json') |>
req_perform()
cont_stat <- resp_body_json(resp_stat)
cont_stat$TopLists[[1]]$StatList |>
bind_rows() |>
clean_names()
#> # A tibble: 10 × 11
#> participant_name particiant_id team_id team_color stat_value sub_stat_value
#> <chr> <int> <int> <chr> <dbl> <dbl>
#> 1 St. Patrick's Ath… 0 1854 #EC1B23 1.4 51
#> 2 Shamrock Rovers 0 4131 #088020 1.4 50
#> 3 Derry City 0 8338 #D80000 1.3 48
#> 4 Waterford FC 0 6042 #185890 1.2 43
#> 5 Drogheda United 0 8339 #7B0047 1.1 41
#> 6 Shelbourne 0 5751 #D01810 1.1 40
#> 7 Sligo Rovers 0 6361 #B81010 1.1 40
#> 8 Bohemian FC 0 4594 #b00017 1.1 39
#> 9 Galway United FC 0 520517 #620531 0.9 33
#> 10 Dundalk 0 1853 #202020 0.6 23
#> # ℹ 5 more variables: minutes_played <int>, matches_played <int>,
#> # stat_value_count <int>, rank <int>, participant_country_code <chr>