使用RVEST从运动参考中删除表格

使用RVEST从运动参考中删除表格,r,web-scraping,rvest,R,Web Scraping,Rvest,我正试图从这个网页上抓取各种表格: 在检查页面的元素时,我发现使用以下代码很容易获得前两个表: ### packages library(tidyverse) library(rvest) ### Scrape offense url_off <- read_html("https://www.pro-football-reference.com/years/2020/") ## AFC Standings url_off %>% html_table

我正试图从这个网页上抓取各种表格:

在检查页面的元素时,我发现使用以下代码很容易获得前两个表:

### packages
library(tidyverse)
library(rvest)

### Scrape offense
url_off <- read_html("https://www.pro-football-reference.com/years/2020/")


## AFC Standings
url_off %>% 
  html_table(fill = TRUE) %>% 
  .[1] %>% 
  as.data.frame()

## NFC Standings
url_off %>% 
  html_table(fill = TRUE) %>% 
  .[2] %>% 
  as.data.frame()

当我尝试从该页面提取任何其他表时,这似乎是一个问题。我能得到的仅有两张表是前两张(上图)。我想不出哪里出了问题。

我已经解决了。数据都存储为注释,我认为这是我的问题。以下是我如何提取表格,以供感兴趣或有类似问题的人使用:

url_off %>%
  html_nodes('#all_team_stats') %>%   
  html_nodes(xpath = 'comment()') %>%
  html_text() %>%
  read_html() %>%
  html_node('table') %>%
  html_table()


url_off %>%
  html_nodes('#all_passing') %>%   
  html_nodes(xpath = 'comment()') %>%
  html_text() %>%
  read_html() %>%
  html_node('table') %>%
  html_table()
url_off %>%
  html_nodes('#all_team_stats') %>%   
  html_nodes(xpath = 'comment()') %>%
  html_text() %>%
  read_html() %>%
  html_node('table') %>%
  html_table()


url_off %>%
  html_nodes('#all_passing') %>%   
  html_nodes(xpath = 'comment()') %>%
  html_text() %>%
  read_html() %>%
  html_node('table') %>%
  html_table()