【发布时间】:2017-12-04 11:41:10
【问题描述】:
我有一个使用 Google 自定义搜索 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
我收到以下响应(这是转换为 PHP 对象的 JSON 响应):
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 自定义搜索吗?
【问题讨论】: