我正在尝试从https://fbref.com/en/comps/9/passing/Premier-League-Stats
我用过
URLPL <- "https://fbref.com/en/comps/9/passing/Premier-League-Stats"
Tab <- htmltab(doc = URLPL, which = 2)
返回
“错误:找不到表。尝试传递(其他)信息到哪个参数”
也是
URLPL <- "https://fbref.com/en/comps/9/passing/Premier-League-Stats"
Tab <- htmltab(doc = URLPL, which = "//table[2]")
返回
“节点[1]中的错误:下标超出范围”
网页上有2个表格。如果有人可以在这里指出我正确的道路。谢谢。
编辑:我现在意识到网页上只有1个表,而我认为不是一个表。现在,我对如何处理此问题感到更加困惑。
在这里回答我自己的问题。对于可能有相同问题的任何人。除了任何体育参考网站上的顶级表格以外的任何内容。 (曲棍球/篮球/棒球)被视为评论。
PremLeague = "https://fbref.com/en/comps/12/stats/La-Liga-Stats"
Prem = PremLeague %>%
read_html %>%
html_nodes(xpath = '//comment()') %>%
html_text() %>%
paste(collapse='') %>%
read_html() %>%
html_node("#stats_standard") %>%
html_table()
这对我有用。