我用下面的代碼:如何獲得谷歌的搜索結果
library(XML)
library(RCurl)
getGoogleURL <- function(search.term, domain = '.co.uk', quotes=TRUE)
{
search.term <- gsub(' ', '%20', search.term)
if(quotes) search.term <- paste('%22', search.term, '%22', sep='')
getGoogleURL <- paste('http://www.google', domain, '/search?q=',
search.term, sep='')
}
getGoogleLinks <- function(google.url)
{
doc <- getURL(google.url, httpheader = c("User-Agent" = "R(2.10.0)"))
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function(...){})
nodes <- getNodeSet(html, "//a[@href][@class='l']")
return(sapply(nodes, function(x) x <- xmlAttrs(x)[[1]]))
}
search.term <- "cran"
quotes <- "FALSE"
search.url <- getGoogleURL(search.term=search.term, quotes=quotes)
links <- getGoogleLinks(search.url)
我想找到所有源於我的搜索鏈接,我得到以下結果:
> links
list()
如何我可以獲得鏈接嗎? 此外,我想獲得谷歌結果的頭條新聞和摘要,我怎樣才能得到它? 終於有辦法獲得ChillingEffects.org結果中的鏈接了嗎?
http://stackoverflow.com/a/22703153/1457051 – hrbrmstr