Search code examples
rweb-scrapingrvest

Using rvest to webscrape player stats


I am trying to webscrape the player stats from this website

https://www.foxsports.com.au/nrl/nrl-premiership/match-centre/NRL20220101/playerstats

I have managed to webscrape a similar website using the following code

page <- read_html("https://www.foxsports.com.au/nrl/nrl-premiership/match-centre/NRL20220101/playerstats")
 
contentnodes <-page %>% html_nodes ("div.l-content.pre-quench") %>% 
  html_attr("q-data") %>% jsonlite::fromJSON()

However I am unable to find what string should replace the "div.l-content.pre-quench" and "q-data" parts as the elements look a little bit different on this page.

Thanks in advance


Solution

  • library(rvest)
    library(tidyverse) 
    
    
    "https://www.foxsports.com.au/nrl/nrl-premiership/match-centre/NRL20220101/playerstats" %>%  
      read_html() %>%  
      html_table() %>% 
      pluck(1) 
    
    # A tibble: 17 × 15
          `` Name                 T     G    RM   PTS   TCK     R   PCM    LB   LBA    TA    KM    FD    SC
       <int> <chr>            <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
     1     1 D. Edwards           0     0   306     0     1    28    55     1     0     0     0     0    77
     2     2 C. Staines           0     0   162     0     3    17    38     0     0     0     0     0    27
     3     3 I. Tago              1     0    80     4    22     9    17     1     0     0     0     0    71
     4     4 S. Crichton          1     4   137    12     8    15    37     1     0     0     0     0    75
     5     5 B. To'o              0     0   188     0     4    20    56     0     0     0     0     0    48
     6     6 J. Luai              1     0    61     4    20     6     9     1     0     0   107     0    59
     7     7 S. O'Sullivan        0     0    49     0    23     6    22     0     2     2   384     1    84
     8     8 M. Leota             0     0    84     0    19    10    26     0     0     0     0     0    31
     9     9 A. Koroisau          1     0    61     4    28     6    22     1     1     1     0     0    91
    10    10 J. Fisher-Harris     0     0   166     0    21    20    53     0     0     0     0     0    51
    11    11 V. Kikau             0     0   138     0    19    15    38     0     1     1    10     0    87
    12    12 L. Martin            1     0    98     4    28    13    37     1     0     0     0     0    80
    13    13 I. Yeo               0     0   129     0    34    13    47     0     0     0     0     0    74
    14    14 M. Kenny             0     0    11     0     6     1     2     0     0     0     0     0     8
    15    15 S. Sorensen          0     0   107     0    22    11    27     0     0     0     0     0    42
    16    16 S. Leniu             0     0    50     0    13     7    14     0     0     0     0     0    23
    17    20 J. Salmon            0     0    25     0    12     3     5     0     0     0    35     0    16