我想从这个页面抓取统计数据:
url <- "http://www.pgatour.com/players/player.20098.stuart-appleby.html/statistics"
具体来说,我想获取 Stuart 头像下方的表格中的数据。标题为“Stuart Appleby - 2015 STATS PGA TOUR”
我尝试将rvest, 与 Selector Gadget ( http://selectorgadget.com/ ) 结合使用。
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")]//td')
'应该'让我得到表格,例如,顶部没有显示“Recap - Rank - Additional Stats”的行
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")] | //th//*[(@id = "playerStats")]//td')
'应该'让我得到带有“Recap - Rank - Add'l Stats”行的表格。
也不行。
Obvs 在网络抓取方面,我完全是新手。当我单击该网页的“查看源代码”时,表格中包含的数据不存在。
在源代码中,我认为应该从表开始,是这段代码:
<script id="playerStatsTourTemplate" type="text/x-jquery-tmpl">
{{each(t, tour) tours}}
{{if pgatour.players.shouldProcessTour(tour.tourCodeLC)}}
<div class="statistics-head">
<h2 class="title">Stuart Appleby - <b>${year} STATS
.
.
.
因此,该表似乎存储在函数无法访问的某个地方(Json?Jquery?Javascript?这些术语是否适用于这里?)html()。有没有办法rvest用来获取这些数据?是否有rvest用于抓取以这种方式存储的数据的等价物?
谢谢。