ZBauc
ZBauc

Reputation: 163

Data Scraping; Extracting links from a table using rvest

I am trying to extract all the player links from this table:

https://www.footballdb.com/players/players.html?letter=A

Here is what my code looks like:

library(rvest)

url <- "https://www.footballdb.com/players/players.html?letter=A"
webpage <- read_html(url)

webpage %>%
  html_nodes("table") %>%
  html_attr("href")

This returns an NA. I've seen other posts with similar questions, but I have been unsuccessful in understanding the answers well enough to apply them to this problem. Any solutions and/or guidance would be much appreciated. Thanks.

Upvotes: 2

Views: 564

Answers (1)

SeGa
SeGa

Reputation: 9809

I think you have to scrape a bit deeper ;)

webpage %>%
  html_nodes("table") %>%
  html_nodes("td") %>% 
  html_nodes("a") %>% 
  html_attr("href")

Upvotes: 5

Related Questions