我知道您正在寻找rvest答案,但这是使用该 XML软件包的另一种方法,它可能比您正在做的更有效。
你见过里面的getLinks()功能example(htmlParse)吗?我使用示例中的这个修改版本来获取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"
# ...
# ...