NB: , , .:)
, , , , ( R, , RCurl XML):
library(RCurl)
library(XML)
get.links.on.page <- function(u) {
doc <- getURL(u)
html <- htmlTreeParse(doc, useInternalNodes = TRUE)
nodes <- getNodeSet(html, "//html//body//a[@href]")
urls <- sapply(nodes, function(x) x <- xmlAttrs(x)[[1]])
urls <- sort(urls)
return(urls)
}
get.root.domain <- function(u) {
root <- unlist(strsplit(u, "/"))[3]
return(root)
}
filter.links <- function(seed, urls) {
urls <- unique(urls)
urls <- urls[which(substr(urls, start = 1, stop = 1) == "h")]
urls <- urls[grep("http", urls, fixed = TRUE)]
seed.root <- get.root.domain(seed)
urls <- urls[-grep(seed.root, urls, fixed = TRUE)]
return(urls)
}
main.fn <- function(seed) {
raw.urls <- get.links.on.page(seed)
filtered.urls <- filter.links(seed, raw.urls)
return(filtered.urls)
}
seed <- "http://www.r-bloggers.com/blogs-list/"
urls <- main.fn(seed)
x <- lapply(as.list(urls[1:3]), main.fn)
names(x) <- urls[1:3]
x
R, x, , .
, !