2017-02-06 29 views
0

完全刮HTML表我用下列R-腳本:不能,使用R

url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3;orderby=default;template=results;type=batting" 
check=readHTMLTable(url,header = T) 
check$"Career summary" 
check<-check$"Career summary" 

我只能湊前11層的意見。

任何人都可以提出爲什麼我無法刮整個表?

+0

工作,有跡象表明,網頁上有多個表。檢查瀏覽器中的頁面。我想你只能得到第一個''標籤的內容 – Wietze314

回答

1

要獲得頁面上的所有表的內容:

library(XML) 

url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3;orderby=default;template=results;type=batting" 

content <- htmlParse(url) 

tbody <- xpathSApply(content, "//tbody") 

lapply(tbody, function(x) readHTMLTable(x, header=T)) 
0

AS @ Wietze314說有一些頁面上的多個表。 你可以得到所有我想你有興趣與表的列表:

url="http://stats.espncricinfo.com/ci/engine/player/253802.html?class=3; 
orderby=default;template=results;type=batting" 

check=htmlParse(url)  

tableNodes <- getNodeSet(check, '//tbody') 
tbList <- lapply(tableNodes, readHTMLTable) 

tbList包含22個data.frames您與

+0

Thanx @Gamba它確實解決了我的問題。你能告訴我這裏的表節點是什麼!? – chdeepak96