R google search results search

A google search with the keywords "medical hospital" returns about 1,150,000,000 results. How can this account be obtained programmatically in R?

I saw this lin k where they try to solve it using Java. How can this be done in R? A sample code snippet will be appreciated.

Thanks.

+6
source share
1 answer

Change only one line of code found in a BioBucket blog post: Get the number of Google searches using R and XML :

GoogleHits <- function(input) { require(XML) require(RCurl) url <- paste("https://www.google.com/search?q=", input, sep = "") # modified line CAINFO = paste(system.file(package="RCurl"), "/CurlSSL/ca-bundle.crt", sep = "") script <- getURL(url, followlocation = TRUE, cainfo = CAINFO) doc <- htmlParse(script) res <- xpathSApply(doc, '//*/div[@id="resultStats"]', xmlValue) cat(paste("\nYour Search URL:\n", url, "\n", sep = "")) cat("\nNo. of Hits:\n") # get rid of cat text if not wanted return(as.integer(gsub("[^0-9]", "", res))) } # Example: no.hits <- GoogleHits("health%20hospital") #Your Search URL: #https://www.google.com/search?q=health%20hospital # #No. of Hits: no.hits #[1] 1170000000 

I changed url destination from

 url <- paste("https://www.google.com/search?q=\"", input, "\"", sep = "") 

to

 url <- paste("https://www.google.com/search?q=", input, sep = "") 
+5
source

Source: https://habr.com/ru/post/987080/


All Articles