Coercing rvest to recognize tables (html_tag(x) == "table" is not TRUE)

时间:2015-07-08 16:02:32

标签: r rvest

I can't seem to ever get html_table() to work.

This is a perfect example: (Trying to scrape the 6 Games: table)

library(rvest)

hockey <- html("http://www.hockey-reference.com/boxscores/2015/3/6/")

hockey %>%
    html_nodes("#stats .tooltip , #stats td , #stats a") %>%
    html_table()

But I am getting a html_tag(x) == "table" is not TRUE. It's so obviously a table.

How can I coerce rvest to recognize the node as a table?

1 个答案:

答案 0 :(得分:8)

尝试:

hockey %>% html_table(fill = TRUE)

解析页面上的所有表格,或

hockey %>% html_nodes("#stats") %>% html_table()

只解析你所追求的第一个。