mcpField
G
Google Search (via Apify)

Google Search (via Apify)

远程服务
apify.com搜索与检索03 周前更新

关于 Google Search (via Apify)

这是一个 Apify Actor,以兼容 Google Custom Search JSON API 的格式返回实时网页和图片搜索结果。开发者和 Agent 可用它替换原端点,并沿用熟悉的请求参数和响应字段。

主要功能

  1. 01兼容 Custom Search JSON 的端点
  2. 02网页和图片搜索结果
  3. 03支持常用搜索参数
  4. 04兼容 SearXNG 的响应路由

适用场景

  1. 01替换 Custom Search API 端点
  2. 02向搜索客户端提供 Google 结果
  3. 03以 JSON 获取图片搜索结果

MCP 相关

可通过 Apify 托管的 MCP 服务使用,让 MCP 客户端和 AI Agent 执行搜索。

配置

远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。

服务地址https://mcp.apify.com/?tools=automationnation/google-custom-search-api
一键复制安装命令
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。

全部服务地址
Streamable HTTPhttps://mcp.apify.com/?tools=automationnation/google-custom-search-api需要授权

工具

详细介绍

Google Custom Search JSON API 替代方案:相同请求,相同 JSON

Run on Apify

Google Custom Search API 替代方案是一个 Apify Actor,可替代 Google 的 Custom Search JSON API。Google 已停止接受新客户,并将于 2027 年 1 月 1 日停用该 API。它使用实时 Google 搜索结果处理相同的 /customsearch/v1 请求,并返回相同的 JSON(包含 title、link、displayLink 和 snippet 的 items,以及图片搜索),每 1,000 次搜索收费 $5,且没有每日上限。

价格: 每 1,000 次搜索(每次最多 10 条结果)收费 $5(Gold 及以上套餐为 $4) · 运行地址: https://apify.com/automationnation/google-custom-search-api · 指南: https://retracn.github.io/automationnation-actors/google-custom-search-api/

快速信息

  • 即插即用端点:将 https://www.googleapis.com/customsearch/v1 替换为 https://automationnation--google-custom-search-api.apify.actor/customsearch/v1,并发送 Apify token(token=… 或 Authorization: Bearer),而不是 key=。
  • 相同参数:q、num、start、gl、hl、lr、cr、safe、dateRestrict、siteSearch、exactTerms、excludeTerms、orTerms、fileType 和 searchType=image(及其图片过滤器);cx 会被接受但忽略。
  • Open WebUI:选择 External web search engine,将 URL 设为 https://automationnation--google-custom-search-api.apify.actor/search,并将 Apify token 作为密钥,这样在 Google PSE 停止接受新客户后仍可使用 Google 搜索结果。
  • 兼容 SearXNG 的路由,适用于 AnythingLLM 和其他 SearXNG 客户端:https://automationnation--google-custom-search-api.apify.actor/searxng?token=YOUR_APIFY_TOKEN 会以 SearXNG 的 JSON 格式返回 Google 搜索结果。
  • 相同 JSON:kind、queries.request 和 nextPage、searchInformation,以及包含 title、htmlTitle、link、displayLink、snippet、htmlSnippet 和 formattedUrl 的 items[](图片结果还包含 mime 和 image.contextLink、width、height、byteSize、thumbnailLink)。
  • 网页搜索使用 Google 的“Web”结果视图:每页 10 条普通结果,不含 AI Overview、广告、视频和论坛信息框,接近该 API 的返回结果。
  • 差异:搜索范围为整个网络(通过 siteSearch 或 site: 运算符传入站点列表),totalResults 是下限,没有 pagemap,且每个请求耗时约 4–10 秒。
  • 价格:每 1,000 次搜索(每次最多 10 条结果)收费 $5,与 Google 的收费相同;没有结果的搜索免费,且没有每日上限。

将其用作即插即用的 Custom Search JSON API

更改端点和密钥;其余代码保持不变:

更改前更改后
端点https://www.googleapis.com/customsearch/v1https://automationnation--google-custom-search-api.apify.actor/customsearch/v1
身份验证key=YOUR_GOOGLE_KEY&cx=YOUR_ENGINE_IDtoken=YOUR_APIFY_TOKEN 或请求头 Authorization: Bearer YOUR_APIFY_TOKEN
curl "https://automationnation--google-custom-search-api.apify.actor/customsearch/v1?q=best+crm+for+startups&num=10&token=$APIFY_TOKEN"

Python(examples/cse_requests.py)和 JavaScript(examples/cse_fetch.mjs)版本位于 examples/ 中。响应是该 API 的 JSON:items[].title、link、displayLink、snippet、queries.nextPage 和 searchInformation;searchType=image 同样可用。

示例输入

{
  "queries": [
    "best project management software"
  ],
  "maxResultsPerQuery": 10
}

通过代码运行

REST API

curl -X POST "https://api.apify.com/v2/acts/automationnation~google-custom-search-api/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"queries": ["best project management software"], "maxResultsPerQuery": 10}'

Python — 参见 examples/python_example.py

# pip install apify-client
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("automationnation/google-custom-search-api").call(run_input={
  "queries": [
    "best project management software"
  ],
  "maxResultsPerQuery": 10
})
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item.get("title"), item.get("link"), item.get("displayLink"), item.get("snippet"))

JavaScript — 参见 examples/node_example.mjs

// npm install apify-client
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_APIFY_TOKEN' });
const run = await client.actor('automationnation/google-custom-search-api').call({
  "queries": [
    "best project management software"
  ],
  "maxResultsPerQuery": 10
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
for (const item of items) console.log(item.title, item.link, item.displayLink, item.snippet);

将其与 AI Agent 配合使用(MCP)

托管 MCP 服务 URL(适用于 Claude、ChatGPT、Cursor 及其他支持远程 MCP 的客户端):

https://mcp.apify.com?tools=automationnation/google-custom-search-api

Claude Desktop / Cursor 的本地配置 — mcp/claude_desktop_config.json:

{
  "mcpServers": {
    "google-custom-search-api": {
      "command": "npx",
      "args": [
        "-y",
        "@apify/actors-mcp-server",
        "--tools",
        "automationnation/google-custom-search-api"
      ],
      "env": {
        "APIFY_TOKEN": "YOUR_APIFY_TOKEN"
      }
    }
  }
}

常见问题

Custom Search JSON API 什么时候会停止工作? Google 已停止向新客户开放该 API,并表示现有客户需在 2027 年 1 月 1 日前迁移到其他方案。

我需要重写代码吗? 不需要。将端点改为 https://automationnation--google-custom-search-api.apify.actor/customsearch/v1,并使用 Apify API token 替代 Google 密钥;参数和 JSON 响应保持不变。

我可以保留 Programmable Search Engine 的网站列表吗? 不能通过 cx 实现,因为 cx 会被忽略。请将一个网站作为 siteSearch 传入,或在查询中添加多个网站,例如 site:a.com OR site:b.com。

费用是多少? 每 1,000 次搜索收费 $5,每次最多返回 10 条结果(Silver 方案收费 $4.50,Gold 及以上方案收费 $4),且没有每日上限。Google 在每天 100 次免费查询后,每 1,000 次收费 $5;Apify 免费方案包含 $5 的月度额度,约可用于 1,000 次搜索。

更多 AutomationNation 内容


此仓库包含使用示例。爬虫本身运行在 Apify 平台 上;你需要一个免费的 Apify 账户和 API 令牌。示例采用 MIT 许可证。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。