Ida*_*dan 11 php google-custom-search
我有一个使用Google Custom Search API的脚本,遍历多个结果页面.
https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=0&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com
https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=10&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com
https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=20&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com
Run Code Online (Sandbox Code Playgroud)
在上面的所有例子中,我得到了适当的回应.查询响应声称搜索结果有17,900个.但是当脚本达到start = 100时:
https://www.googleapis.com/customsearch/v1?key=[[KEY]]&num=10&hl=en&start=100&cx=[[CX]]&q=%22bank%22&sort=date&googlehost=www.google.com
Run Code Online (Sandbox Code Playgroud)
我收到以下响应(这是转换为PHP对象的JSON响应):
stdClass Object (
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => invalid
[message] => Invalid Value
)
)
[code] => 400
[message] => Invalid Value
) )
Run Code Online (Sandbox Code Playgroud)
尽管我在start = 90中收到的结果声称下一页存在:
"nextPage": [
{
"title": "Google Custom Search - \"bank\"",
"totalResults": "17900",
"searchTerms": "\"bank\"",
"count": 10,
"startIndex": 100,
"inputEncoding": "utf8",
"outputEncoding": "utf8",
"safe": "off",
"cx": "[[CX VALUE]]",
"sort": "date",
"googleHost": "www.google.com",
"hl": "en"
}
]
Run Code Online (Sandbox Code Playgroud)
使用API会显示在start = 92时会出现此无效值错误.此外,这是每个关键字搜索出现此错误的确切页面.任何有关该问题的帮助将不胜感激.这是因为这是Google自定义搜索的免费版本吗?
Don*_*nic 15
这个信息根本不容易找到,我发现它只在google.com上的一个地方正式提到.我在自定义搜索JSON API文档中找到了一行描述nextPage响应元素:
注意:此API仅返回前100个结果.
没有提到这仅限于免费的API.我还发现用户报告确认即使您注册结算也适用该限制,例如,请参阅此相关的SO问题和链接的博客文章.
OTOH 100个查询 /日限制(与您所看到的结果限制相反)有详细记录,并且有关于如何绕过该地方的信息(当然,通过注册结算).