简体   繁体   中英

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

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?

Try either:

hockey %>% html_table(fill = TRUE)

to parse all the tables on the page, or

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

to parse just the first one you're after.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM