我怎样才能抓取这些数据?
How can I scrape this data?
我想从此页面抓取统计信息:
url <- "http://www.pgatour.com/players/player.20098.stuart-appleby.html/statistics"
具体来说,我想获取 Stuart 头像下方 table 中的数据。它的标题是 "Stuart Appleby - 2015 STATS PGA TOUR"
我尝试将 rvest
与选择器小工具 (http://selectorgadget.com/) 结合使用。
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")]//td')
'Should' 给我 table 没有,例如,上面写着 "Recap -- Rank -- Additional Stats"
的行
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")] | //th//*[(@id = "playerStats")]//td')
'Should' 用 "Recap -- Rank -- Add'l Stats" 行给我 table。
也没有。
Obvs 在网络抓取方面我完全是个新手。当我单击该网页的 'view source' 时,table 中包含的数据不存在。
在源代码中,我认为 table 应该开始的地方是这段代码:
<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
.
.
.
因此,table 似乎存储在某处(Json?Jquery?Javascript?这些术语是否适用于此处?) html()
函数。无论如何使用 rvest
来获取这些数据?是否有 rvest
等同于获取以这种方式存储的数据?
谢谢。
我可能会使用该页面发出的 GET 请求从他们的 API 中获取原始数据并着手解析...
content(a)
给你一个列表表示...基本上是 fromJSON()
的输出
或者
as(a, "character")
给你原始的 JSON
library("httr")
a <- GET("http://www.pgatour.com/data/players/20098/2014stat.json")
content(a)
as(a, "character")
看看这个。
关于 GitHub 抓取 PGA 数据的开源项目:https://github.com/zachwill/golf/blob/master/pga.py
我想从此页面抓取统计信息:
url <- "http://www.pgatour.com/players/player.20098.stuart-appleby.html/statistics"
具体来说,我想获取 Stuart 头像下方 table 中的数据。它的标题是 "Stuart Appleby - 2015 STATS PGA TOUR"
我尝试将 rvest
与选择器小工具 (http://selectorgadget.com/) 结合使用。
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")]//td')
'Should' 给我 table 没有,例如,上面写着 "Recap -- Rank -- Additional Stats"
的行url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")] | //th//*[(@id = "playerStats")]//td')
'Should' 用 "Recap -- Rank -- Add'l Stats" 行给我 table。
也没有。
Obvs 在网络抓取方面我完全是个新手。当我单击该网页的 'view source' 时,table 中包含的数据不存在。
在源代码中,我认为 table 应该开始的地方是这段代码:
<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
.
.
.
因此,table 似乎存储在某处(Json?Jquery?Javascript?这些术语是否适用于此处?) html()
函数。无论如何使用 rvest
来获取这些数据?是否有 rvest
等同于获取以这种方式存储的数据?
谢谢。
我可能会使用该页面发出的 GET 请求从他们的 API 中获取原始数据并着手解析...
content(a)
给你一个列表表示...基本上是 fromJSON()
的输出
或者
as(a, "character")
给你原始的 JSON
library("httr")
a <- GET("http://www.pgatour.com/data/players/20098/2014stat.json")
content(a)
as(a, "character")
看看这个。
关于 GitHub 抓取 PGA 数据的开源项目:https://github.com/zachwill/golf/blob/master/pga.py