I am using a function I found on a Duke Sports Analytics site to scrape college basketball games from sportsreference.com. It takes a url as an argument. The code below scrapes all games for Duke from 2011-2022. I have a list of multiple teams (Duke, Baylor, Kansas, Gonzaga). I need to substitute "duke" within the url being concatenated with the 4 team names I listed. How could I alter this code to loop through all those teams, and not just Duke which is hardcoded into the code?
teams <- as.list(c("Gonzaga", "Baylor", "Kansas", "Duke"))
game_logs <- tibble(
season_url = 2011:2022,
season = paste0(season_url - 1, "-", str_sub(season_url, start = 3)),
url = paste0("https://www.sports-reference.com/cbb/schools/duke/", season_url, "-
schedule.html")
) %>%
mutate(data = map(url, possibly(scrape_game_logs, otherwise = NA)))