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

喜欢而已 提交于 2019-12-04 14:06:02

问题


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:


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.



来源:https://stackoverflow.com/questions/31297911/coercing-rvest-to-recognize-tables-html-tagx-table-is-not-true

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!