【发布时间】:2015-06-13 15:32:18
【问题描述】:
我想从这个页面抓取统计数据:
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”行的表格。
也不行。
在网络抓取方面,我完全是新手。当我点击该网页的“查看源代码”时,表格中包含的数据不存在。
在我认为表格应该开始的源代码中,是这段代码:
<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
.
.
.
因此,该表似乎存储在 html() 函数无法访问的某处(Json?Jquery?Javascript?这些术语是否适用于此处?)。有没有办法使用rvest 来获取这些数据?是否有 rvest 等效项用于抓取以这种方式存储的数据?
谢谢。
【问题讨论】:
-
任何帮助您的人都违反了他们的 ToC -
You shall not use or permit or facilitate others to use PGATOUR.com by automated electronic processes, robots, spiders, scrapers, webcrawlers, or other computer programs that monitor, copy or download data or other content found on or accessed through PGATOUR.com, including without limitation real time scoring, video, audio, statistics, polling, or data content, whether current or archival.
标签: r web-scraping rvest