我知道您正在寻找rvest
答案,但这里有另一种方法,使用XML
程序包,可能比您所做的更有效。
你见过example(htmlParse)
的getLinks()
函数吗?我从示例中使用此修改后的版本获取href
链接。它是一个处理函数,所以我们可以在读取数据时收集这些值,节省内存并提高效率。
links <- function(URL)
{
getLinks <- function() {
links <- character()
list(a = function(node, ...) {
links <<- c(links, xmlGetAttr(node, "href"))
node
},
links = function() links)
}
h1 <- getLinks()
htmlTreeParse(URL, handlers = h1)
h1$links()
}
links("http://www.bvl.com.pe/includes/empresas_todas.dat")
# [1] "/inf_corporativa71050_JAIME1CP1A.html"
# [2] "/inf_corporativa10400_INTEGRC1.html"
# [3] "/inf_corporativa66100_ACESEGC1.html"
# [4] "/inf_corporativa71300_ADCOMEC1.html"
# [5] "/inf_corporativa10250_HABITAC1.html"
# [6] "/inf_corporativa77900_PARAMOC1.html"
# [7] "/inf_corporativa77935_PUCALAC1.html"
# [8] "/inf_corporativa77600_LAREDOC1.html"
# [9] "/inf_corporativa21000_AIBC1.html"
# ...
# ...
'rvest'使用'XML'包提取节点。它真的不应该更快。 – hrbrmstr 2014-12-04 17:18:41