Created
January 22, 2011 22:26
-
-
Save drewconway/791559 to your computer and use it in GitHub Desktop.
Function takes a string as parameter and returns the approximate number of Google search results containing that string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(RCurl) | |
require(XML) | |
google.counts<-function(s){ | |
search.url<-paste("http://www.google.com/search?q=",gsub(" ","+",s),sep="") | |
search.html<-getURL(search.url) | |
parse.search<-htmlTreeParse(search.html,useInternalNodes = TRUE) | |
search.nodes<-getNodeSet(parse.search,"//div[@id='resultStats']") | |
search.value<-strsplit(xmlValue(search.nodes[[1]])," ",fixed=TRUE)[[1]][2] | |
return(as.numeric(gsub(",","",search.value,fixed=TRUE))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment