Skip to content

Instantly share code, notes, and snippets.

@CarlBoneri
Created March 20, 2018 19:05
Show Gist options
  • Save CarlBoneri/912e79c72a21963c8dd7cff82fb2665a to your computer and use it in GitHub Desktop.
Save CarlBoneri/912e79c72a21963c8dd7cff82fb2665a to your computer and use it in GitHub Desktop.
title author date output
SGAA_THANGZ
Carl Boneri
March 20, 2018
html_document
highlight keep_md number_sections theme toc
espresso
true
true
spacelab
true
<style> .main-container { max-width: 75vw !important; margin-left: auto; margin-right: auto; } </style>
sgaa_url <- 'https://www.sgaasports.com/stats/league_instance/62008?subseason=481559&tab=league_instance_team_stats&tool=2735801'
d <- read_html(sgaa_url) %>% 
  xml_find_all(".//table[contains(@id,'team_stats')]//tr//td//a[@class='teamName']")

page_link <- xml_attr(d, "href")
team_name <- xml_attr(d, "title")

team_name <- gsub('^(\\w+)(\\s)', "", team_name, perl = T)

roster_link <- stri_replace_all_regex(
  page_link, c("page", "\\-(.*?)(?=\\?)"), c("roster",""), 
  vectorize_all = F)

schedule_links <- lapply(page_link, function(i){
  path <- read_html(i) %>% xml_find_all(".//li[contains(@id,'schedule')]//a")
  sched_path <- url_absolute(xml_attr(path, "href"),'https://www.sgaasports.com')
  read_html(sched_path) %>% xml_find_all(".//table") %>% html_table %>% .[[1]] %>% 
    mutate_all(function(x){
      gsub("(\\s+)?\n(\\s+)?", "", x,perl = T) %>% stri_trim_both()
    })
})

players <- lapply(roster_link, function(i){
  read_html(i) %>% xml_find_all(".//table") %>% html_table() %>% 
    .[[1]] %>% select(Name)
})

lapply(1:length(team_name), function(j){
  setNames(list(list(roster = players[[j]], schedule = schedule_links[[j]])), team_name[[j]])
}) %>% unlist(recursive = F)
## $`Mike Azarian`
## $`Mike Azarian`$roster
##            Name
## 1  Mike Azarian
## 2   Ryan Dodson
## 3 Tyler Douglas
## 4   Donnie Hall
## 5  Ricky Harbel
## 6 Andy Matthews
## 7    Nik Nemeth
## 8   Chris Treft
## 9  Carter Watts
## 
## $`Mike Azarian`$schedule
##          Date Result          Opponent        Location      Status
## 1  Tue Jan 30  L1-11       Kevin Casey                            
## 2  Tue Feb  6   L5-6       @KC Watkins                            
## 3  Tue Feb 13   L4-7      @Connor Hall                            
## 4  Tue Feb 20      -  Kevin Casey(1-2)                 8:00 PM EST
## 5  Tue Feb 27      -  @KC Watkins(2-1)                 9:00 PM EST
## 6  Tue Mar  6      -  Kevin Casey(1-2)                 8:00 PM EST
## 7  Tue Mar 13      -  @KC Watkins(2-1) SGAA White Rink 8:00 PM EDT
## 8  Tue Mar 20      -  Connor Hall(3-0) SGAA White Rink 8:00 PM EDT
## 9  Tue Mar 27      -  Kevin Casey(1-2) SGAA White Rink 8:00 PM EDT
## 10 Tue Apr  3      - @Connor Hall(3-0) SGAA White Rink 9:00 PM EDT
## 
## 
## $`KC Watkins`
## $`KC Watkins`$roster
##              Name
## 1  Brian Atkinson
## 2     Carl Boneri
## 3 Leeila  Cashner
## 4      Lee Garmon
## 5    Hugh Ratigan
## 6   Hyatt Ratigan
## 7    Neil Ratigan
## 8      Will Remar
## 9      KC Watkins
## 
## $`KC Watkins`$schedule
##          Date Result          Opponent        Location      Status
## 1  Tue Jan 30   L4-7      @Connor Hall                            
## 2  Tue Feb  6   W6-5      Mike Azarian                            
## 3  Tue Feb 13   W5-2       Kevin Casey                            
## 4  Tue Feb 20      - @Connor Hall(3-0)                 9:00 PM EST
## 5  Tue Feb 27      - Mike Azarian(0-2)                 9:00 PM EST
## 6  Tue Mar  6      - @Connor Hall(3-0)                 9:00 PM EST
## 7  Tue Mar 13      - Mike Azarian(0-2) SGAA White Rink 8:00 PM EDT
## 8  Tue Mar 20      -  Kevin Casey(1-2) SGAA White Rink 9:00 PM EDT
## 9  Tue Mar 27      - @Connor Hall(3-0) SGAA White Rink 9:00 PM EDT
## 10 Tue Apr  3      - @Kevin Casey(1-2) SGAA White Rink 8:00 PM EDT
## 
## 
## $`Kevin Casey`
## $`Kevin Casey`$roster
##              Name
## 1     Mark Arthur
## 2    Keith Atkins
## 3     Pete Branch
## 4     Will Branch
## 5     Kevin Casey
## 6    Mike Johnson
## 7   Jeff Rossmann
## 8 MItchell Semedo
## 
## $`Kevin Casey`$schedule
##          Date Result           Opponent        Location      Status
## 1  Tue Jan 30  W11-1      @Mike Azarian                            
## 2  Tue Feb  6   L6-9       @Connor Hall                            
## 3  Tue Feb 13   L2-5        @KC Watkins                            
## 4  Tue Feb 20      - @Mike Azarian(0-2)                 8:00 PM EST
## 5  Tue Feb 27      -  @Connor Hall(3-0)                 8:00 PM EST
## 6  Tue Mar  6      - @Mike Azarian(0-2)                 8:00 PM EST
## 7  Tue Mar 13      -   Connor Hall(3-0) SGAA White Rink 9:00 PM EDT
## 8  Tue Mar 20      -   @KC Watkins(2-1) SGAA White Rink 9:00 PM EDT
## 9  Tue Mar 27      - @Mike Azarian(0-2) SGAA White Rink 8:00 PM EDT
## 10 Tue Apr  3      -    KC Watkins(2-1) SGAA White Rink 8:00 PM EDT
## 
## 
## $`Connor Hall`
## $`Connor Hall`$roster
##              Name
## 1 Jackson Cochran
## 2   Kevin Goodwin
## 3     Connor Hall
## 4       Jake Ivey
## 5  Jesse Mitchell
## 6   Dylan Pilgrim
## 7       Matt Roon
## 8    Jonny Walker
## 9  Chase Williams
## 
## $`Connor Hall`$schedule
##          Date Result           Opponent        Location      Status
## 1  Tue Jan 30   W7-4         KC Watkins                            
## 2  Tue Feb  6   W9-6        Kevin Casey                            
## 3  Tue Feb 13   W7-4       Mike Azarian                            
## 4  Tue Feb 20      -    KC Watkins(2-1)                 9:00 PM EST
## 5  Tue Feb 27      -   Kevin Casey(1-2)                 8:00 PM EST
## 6  Tue Mar  6      -    KC Watkins(2-1)                 9:00 PM EST
## 7  Tue Mar 13      -  @Kevin Casey(1-2) SGAA White Rink 9:00 PM EDT
## 8  Tue Mar 20      - @Mike Azarian(0-2) SGAA White Rink 8:00 PM EDT
## 9  Tue Mar 27      -    KC Watkins(2-1) SGAA White Rink 9:00 PM EDT
## 10 Tue Apr  3      -  Mike Azarian(0-2) SGAA White Rink 9:00 PM EDT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment