Xml 从R中的网页返回链接列表
我试图在r中编写一个函数,给定一个地址,它将返回该网页上的链接列表 例如:Xml 从R中的网页返回链接列表,xml,r,web-scraping,Xml,R,Web Scraping,我试图在r中编写一个函数,给定一个地址,它将返回该网页上的链接列表 例如: getLinks("http://prog21.dadgum.com/109.html") 将返回: "http://prog21.dadgum.com/prog21.css" "http://prog21.dadgum.com/atom.xml" "http://prog21.dadgum.com/index.html" "http://prog21.dadgum.com/archives.html" "http:/
getLinks("http://prog21.dadgum.com/109.html")
将返回:
"http://prog21.dadgum.com/prog21.css"
"http://prog21.dadgum.com/atom.xml"
"http://prog21.dadgum.com/index.html"
"http://prog21.dadgum.com/archives.html"
"http://prog21.dadgum.com/atom.xml"
"http://prog21.dadgum.com/56.html"
"http://prog21.dadgum.com/39.html"
"http://prog21.dadgum.com/109.html"
"http://prog21.dadgum.com/108.html"
"http://prog21.dadgum.com/107.html"
"http://prog21.dadgum.com/106.html"
"http://prog21.dadgum.com/105.html"
"http://prog21.dadgum.com/104.html"
此函数似乎适用于其他网页,但由于某些原因,它不会返回有关网页的完整URL。我很想知道是否有更好的方法
getLinks <- function(URL) {
require(XML)
doc <- htmlParse(URL)
out <- unlist(doc['//@href'])
names(out) <- NULL
out
}
getLinks