我有一个脚本,使用谷歌自定义搜索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
在上述所有示例中,我都获得了适当的响应。查询响应声称有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
我收到了以下响应(这是JSON响应转换为PHP对象的结果):
stdClass Object (
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => global
[reason] => invalid
[message] => Invalid Value
)
)
[code] => 400
[message] => Invalid Value
) )
尽管我在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"
}
]
使用API进行测试发现,当start=92时会出现无效值错误。此外,每次关键字搜索都会在该页面上出现此错误。如能提供帮助解决问题将不胜感激。这是因为这是Google自定义搜索的免费版本吗?