I am trying to scrape the table from the following webpage using R:
https://baseballsavant.mlb.com/leaderboard/home-runs?player_type=Batter&team=&min=0&cat=adj_xhr&year=2020
When inspecting the webpage, this is what I see in the HTML code:
The SelectorGadget just calls it “table”. However, I am having trouble extracting the table into R studio. This is what I am trying now:
<code>install.packages("rvest")
install.packages("dplyr")
library(rvest)
library(dplyr)
url <- "https://baseballsavant.mlb.com/leaderboard/home-runs?player_type=Batter&team=&min=0&cat=adj_xhr&year=2020"
# Read the webpage
webpage <- read_html(url)
# Extract the table
table <- webpage %>%
html_node(xpath = '//*[@id="homeruns"]/table') %>%
html_table()
# View the table
print(table)
</code>
<code>install.packages("rvest")
install.packages("dplyr")
library(rvest)
library(dplyr)
url <- "https://baseballsavant.mlb.com/leaderboard/home-runs?player_type=Batter&team=&min=0&cat=adj_xhr&year=2020"
# Read the webpage
webpage <- read_html(url)
# Extract the table
table <- webpage %>%
html_node(xpath = '//*[@id="homeruns"]/table') %>%
html_table()
# View the table
print(table)
</code>
install.packages("rvest")
install.packages("dplyr")
library(rvest)
library(dplyr)
url <- "https://baseballsavant.mlb.com/leaderboard/home-runs?player_type=Batter&team=&min=0&cat=adj_xhr&year=2020"
# Read the webpage
webpage <- read_html(url)
# Extract the table
table <- webpage %>%
html_node(xpath = '//*[@id="homeruns"]/table') %>%
html_table()
# View the table
print(table)
Any help would be greatly appreciated!