强制 rvest 识别表格(html_tag(x) == "table" is not TRUE) [英] Coercing rvest to recognize tables (html_tag(x) == "table" is not TRUE)

查看:43
本文介绍了强制 rvest 识别表格(html_tag(x) == "table" is not TRUE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让 html_table() 工作.

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

这是一个完美的例子:(试图刮 6 个游戏:表)

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()

但我得到一个 html_tag(x) == "table" is not TRUE.很明显是一张桌子.

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

如何强制 rvest 将节点识别为表?

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

推荐答案

尝试:

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.

这篇关于强制 rvest 识别表格(html_tag(x) == "table" is not TRUE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆