gpt4 book ai didi

r 谷歌搜索结果计数检索

转载 作者:行者123 更新时间:2023-12-04 09:40:41 25 4
gpt4 key购买 nike

关闭。这个问题需要更多focused .它目前不接受答案。












想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post .

6年前关闭。




Improve this question




用关键字“健康医院”搜索谷歌会返回大约 1,150,000,000 个结果。如何在 R 中以编程方式获得此计数?

我见过这个 lin k 他们尝试使用 Java 解决它的地方。这如何在 R 中完成?示例代码片段将不胜感激。

谢谢。

最佳答案

仅修改 BioBucket 博客文章中的一行代码:Get No. of Google Search Hits with 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

我换了 url分配来自
url <- paste("https://www.google.com/search?q=\"", input, "\"", sep = "")


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

关于r 谷歌搜索结果计数检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30199157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com