I want to search some thing in yahoo and want to get links :
ex : search by sap wiki and want to get output like
https://en.wikipedia.org/wiki/SAP_ERP
basically I am following this question : How to get google search results my code is :
library(XML) #
library(xml2) #
library(RCurl) #
myOpts <- curlOptions(connecttimeout = 900000000000) #
getyahooURL <- function(search.term, domain = '.com', quotes=TRUE) #
{ #
search.term <- gsub(' ', '%20', search.term) #
if(quotes) search.term <- paste('%22', search.term, '%22', sep='') #
getyahooURL <- paste('http://in.search.yahoo',
domain, '/search;_ylt=A0oG7l7PeB5P3G0AKASl87UF?p=', #
search.term,'&fr2=sb-top-in.search&fr=yfp-t-101&vm=r',
sep='') #
} # #
getyahooLinks <- function(yahoo.url) { #
doc <- getURL(yahoo.url, httpheader = c("User-Agent" = "R #
(2.10.0)"),.opts = myOpts) #
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function #
(...){}) #
nodes <- getNodeSet(html, "//h3[@class='title']//a") #
return(sapply(nodes, function(x) x <- xmlAttrs(x)[["href"]])) #
}
but I am getting empty list as a output.
> links
list()
thanks..