Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 266
emehex Avatar asked Dec 25 '22 17:12

emehex


1 Answers

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.

like image 108
joran Avatar answered Feb 13 '23 02:02

joran