You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Custom Search JSON API查询已收录URL却返回0结果的解决方案

解决Google Custom Search JSON API返回totalResults:0但手动可找到页面的问题

针对你遇到的API返回结果与手动搜索不一致的问题,可尝试以下解决方案:

  • 修正site查询语法
    site:运算符的正确用法是后跟域名,而非完整URL。若要精准匹配目标页面,可将完整URL用双引号包裹作为搜索词,或拆分站点与页面关键词:
    示例请求1(精确匹配URL):

    GET https://www.googleapis.com/customsearch/v1?q="https://diario24horas.com/madrid/consigue-un-cabello-liso-y-saludable-con-un-alisado-permanente-organico-en-dim-salon/"&key=API_KEY&cx=MY_cx
    

    示例请求2(限定站点+页面关键词):

    GET https://www.googleapis.com/customsearch/v1?q="consigue-un-cabello-liso-y-saludable-con-un-alisado-permanente-organico-en-dim-salon" site:diario24horas.com&key=API_KEY&cx=MY_cx
    
  • 检查自定义搜索引擎配置
    登录Google自定义搜索控制台,确认你的cx对应的引擎是否允许搜索目标站点:

    • 若设置为“特定网站”,需确保diario24horas.com已添加到允许列表;
    • 若需搜索全网,可将配置改为“搜索整个网络”。
  • 确保URL参数正确编码
    手动构造请求时,q参数中的特殊字符(如斜杠/、连字符-)需进行URL编码。例如原URL中的/应编码为%2F,编码后的请求示例:

    GET https://www.googleapis.com/customsearch/v1?q=%22https%3A%2F%2Fdiario24horas.com%2Fmadrid%2Fconsigue-un-cabello-liso-y-saludable-con-un-alisado-permanente-organico-en-dim-salon%2F%22&key=API_KEY&cx=MY_cx
    
  • 排查缓存与调用限制

    • 谷歌搜索结果存在缓存机制,API返回可能滞后于实时搜索,可间隔一段时间后重试;
    • 确认未超出API调用限额,超限通常会返回明确错误,但也可能影响结果返回逻辑。

内容的提问来源于stack exchange,提问作者Marcos Canto Moreno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:22:39