我想從這個網頁刮統計:如何刮取這些數據?
url <- "http://www.pgatour.com/players/player.20098.stuart-appleby.html/statistics"
具體來說,我要搶在這司徒爆頭下面的表中的數據。它是「Stuart Appleby - 2015 STATS PGA TOUR」的頭條新聞。
我嘗試使用rvest
,與Selector Gadget(http://selectorgadget.com/)組合使用。
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")]//td')
「應該」讓我的表沒有,例如,在頂部有一行寫着「重溫 - 等級 - 更多統計」
url_html <- url %>% html()
url_html %>%
html_nodes(xpath = '//*[(@id = "playerStats")] | //th//*[(@id = "playerStats")]//td')
「應該」讓我用表即「重述 - 排名 - 添加統計」行。
也沒有。
Obvs我是一個完整的newb當涉及到網絡抓取。當我點擊該網頁的「查看源代碼」時,表中包含的數據不存在。
在源代碼中,在那裏我認爲表應該開始,是這段代碼:
<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
等同於抓取以這種方式存儲的數據?
謝謝。
任何人誰可以幫助你違反了他們的ToC的 - '你不得使用或允許或協助他人通過自動化的電子流程,機器人使用PGATOUR.com,監視,複製或下載在PGATOUR.com上找到或通過PGATOUR.com訪問的數據或其他內容,包括但不限於實時評分,視頻,音頻,統計數據,輪詢或數據內容(無論是當前的或檔案.' – hrbrmstr