1

我想在雅虎搜索一些东西并想获得链接:

例如:通过 sap wiki 搜索并希望获得类似的输出

https://en.wikipedia.org/wiki/SAP_ERP

基本上我在关注这个问题: 如何获取谷歌搜索结果 我的代码是:

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"]]))                #
}

但我得到空列表作为输出。

> links
list()

谢谢..

4

0 回答 0