首页 > 解决方案 > UseMethod(“html_table”)中的错误:没有适用于“html_table”的方法应用于“xml_missing”类的对象

问题描述

我正在尝试从https://www.sports-reference.com/cbb/schools/bethune-cookman/2020-schedule.html中删除日程表,并且我看到了其他解决同一主题的问题,但是当我遵循该代码(如下)时,它仍然给我标题中的错误。有什么我想念的吗?

library(rvest)
url <- 'https://www.sports-reference.com/cbb/schools/bethune-cookman/2020-schedule.html'
schedule <- url %>%
             read_html %>%
             html_nodes(xpath = '//comment()') %>%
             html_text() %>%
             paste(collapse='') %>%
             read_html() %>%
             html_node('table#schedule') %>%
             html_table()

标签: rweb-scrapingrvest

解决方案


此表不在评论中。尝试 -

library(rvest)
url <- 'https://www.sports-reference.com/cbb/schools/bethune-cookman/2020-schedule.html'
schedule <- url %>% read_html %>%  html_node('table#schedule') %>% html_table() 
schedule

# A tibble: 30 x 15
#       G Date   Time  Type  ``    Opponent Conf  ``       Tm   Opp OT        W     L
#   <int> <chr>  <chr> <chr> <chr> <chr>    <chr> <chr> <int> <int> <chr> <int> <int>
# 1     1 Wed, … 7:00p REG   ""    Johnson… ""    W       110    68 ""        1     0
# 2     2 Sat, … 8:00p REG   "@"   Texas T… "Big… L        44    79 ""        1     1
# 3     3 Mon, … 8:30p REG   "@"   Omaha    "Sum… L        61    90 ""        1     2
# 4     4 Fri, … 7:00p REG   ""    Trinity… ""    W       100    42 ""        2     2
# 5     5 Fri, … 1:00p REG   "@"   Incarna… "Sou… W        83    58 ""        3     2
# 6     6 Sat, … 1:00p REG   "N"   Eastern… "OVC" W        66    63 ""        4     2
# 7     7 Sun, … 1:00p REG   "N"   St. Fra… ""    W        74    70 ""        5     2
# 8     8 Sun, … 6:00p REG   "@"   Georgia… "ACC" L        65    68 ""        5     3
# 9     9 Tue, … 7:00p REG   "@"   Stetson  "A-S… L        67    72 ""        5     4
#10    10 Sat, … 6:00p REG   "@"   Jackson… "A-S… L        60    82 ""        5     5
# … with 20 more rows, and 2 more variables: Streak <chr>, Arena <chr>

推荐阅读