我正在使用带有以下代码的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()而不提取任何元素。
发布于 2018-06-25 22:45:26
查看该网站的源代码,您可以看到该表实际上并不存在于HTML源代码中--它是使用JavaScript动态生成的。这就是为什么您的XPath查询返回一个空<div>。
因此,您不能依赖{ JavaScript },在这种情况下,您需要使用可以解释rvest的动态刮板,如{RSelenium}。
https://stackoverflow.com/questions/51025719
复制相似问题