如何使用 XML 包抓取 html 表?
以维基百科页面为例巴西足球队 http://en.wikipedia.org/wiki/Brazil_national_football_team。我想在 R 中阅读它并获取“巴西与 FIFA 认可球队对阵的所有比赛列表”表作为数据框。我怎样才能做到这一点?
…或更短的尝试:
library(XML)
library(RCurl)
library(rlist)
theurl <- getURL("https://en.wikipedia.org/wiki/Brazil_national_football_team",.opts = list(ssl.verifypeer = FALSE) )
tables <- readHTMLTable(theurl)
tables <- list.clean(tables, fun = is.null, recursive = FALSE)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))
所选表格是页面上最长的表格
tables[[which.max(n.rows)]]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)