【发布时间】:2019-10-04 12:32:41
【问题描述】:
在浏览器 (Chrome) 和 R 中提交完全相同的 Google Search API 查询会返回不同数量的结果。这可能是什么原因?唯一明显的区别是我从我的计算机(基于英国)在浏览器中提交查询,而 R 结果来自基于 NL 的 GCE VM。即使我在查询字符串中指定了搜索的国家,这可能是原因吗?
# Pasted in the browser address bar
https://www.googleapis.com/customsearch/v1?q=%22KALLIGIANNIS%22%20Rethymno&num=10&lr=lang_en&cx=SSS&gl=gr&cr=countryGR&dateRestrict=date:r:20150831:20170831&key=XXX&alt=json
# Get request in R
httr::GET('https://www.googleapis.com/customsearch/v1?q=%22KALLIGIANNIS%22%20Rethymno&num=10&lr=lang_en&cx=SSS&gl=gr&cr=countryGR&dateRestrict=date:r:20150831:20170831&key=XXX&alt=json')
浏览器中显示的结果:
"searchInformation": {
"searchTime": 0.133114,
"formattedSearchTime": "0.13",
"totalResults": "109",
"formattedTotalResults": "109"
R中的结果
oneresult <- GET('https://www.googleapis.com/customsearch/v1?q=%22KALLIGIANNIS%22%20Rethymno&num=10&lr=lang_en&cx=SSS&gl=gr&cr=countryGR&dateRestrict=date:r:20150831:20170831&key=XXX&alt=json')
content(oneresult)[[5]]
$searchTime
[1] 0.584238
$formattedSearchTime
[1] "0.58"
$totalResults
[1] "59"
$formattedTotalResults
[1] "59"
【问题讨论】:
-
google 搜索算法是一个黑盒子。它会根据地理位置和其他参数产生不同的结果,但并非所有这些都是已知的。例如,在常规模式和隐身模式下使用浏览器(不是通过 googleapis)也可能会产生不同的结果。我的猜测是您的假设是正确的(差异是由搜索来源的位置引起的)。
-
谢谢,阿迪。如果没有其他人插话,我想就是这样。不妨发表您的评论作为答案。
-
发布了,虽然这不是一个确定的答案...
标签: r google-search-api