网络抓取足球数据不会返回任何内容

时间:2018-06-25 14:20:56

标签: r rvest

我想从网站https://www.whoscored.com/Regions/247/Tournaments/36/Seasons/5967/Stages/15737/Fixtures/International-FIFA-World-Cup-2018抓取匹配结果表

我正在使用带有以下代码的rvest软件包:

library(rvest)

url.tournament <- "https://www.whoscored.com/Regions/247/Tournaments/36/Seasons/5967/Stages/15737/Fixtures/International-FIFA-World-Cup-2018"
df.tournament <- read_html(url.tournament) %>%
                  html_nodes(xpath='//*[@id="tournament-fixture-wrapper"]') %>%
                  html_nodes("table")
                  html_table()

没有提取任何元素。

1 个答案:

答案 0 :(得分:3)

查看网站的源代码,您可以看到该表实际上并不存在于HTML源代码中-它是使用JavaScript动态生成的。因此,您的XPath查询返回空的<div>

因此,在这种情况下,您不能依靠{rvest},需要使用诸如{RSelenium}之类的动态抓取工具来解释JavaScript。

相关问题