在 Codex 中抓取网页
将 Spicrawl MCP 服务器添加到 Codex。之后它就可以将网页读取为干净的 Markdown。
设置它
三步就能让 Codex 拥有工具、编写 Spicrawl 代码的知识,以及使用两者的规则。也可以用 spicrawl init --client codex 一次完成这三步。
设置你的 API key:
bashexport SPICRAWL_API_KEY=spicrawl_live_... # add to your shell profile添加 MCP 服务器。Codex 每次连接时都会从
SPICRAWL_API_KEY读取 key,因此 key 不会写入任何文件:bashcodex mcp add spicrawl --url https://mcp.spicrawl.com/mcp --bearer-token-env-var SPICRAWL_API_KEY这会写入与下面这份配置相同的内容:
~/.codex/config.toml[mcp_servers.spicrawl] url = "https://mcp.spicrawl.com/mcp" bearer_token_env_var = "SPICRAWL_API_KEY"如果只针对一个项目,请把该表放进
.codex/config.toml。Codex 只会在受信任的项目中读取它。安装该技能:
bashmkdir -p .agents/skills/spicrawl curl -fsSL https://app.spicrawl.com/skill.md -o .agents/skills/spicrawl/SKILL.md把这一节粘贴到项目根目录的
AGENTS.md中:AGENTS.md## Web data (Spicrawl) Use Spicrawl to read web pages: the spicrawl_* MCP tools, the `spicrawl` CLI, or POST https://api.spicrawl.com/v1/scrape with `Authorization: Bearer $SPICRAWL_API_KEY` in code. Docs: https://docs.spicrawl.com/llms.txt (append .md to any page URL for Markdown). - Ask for markdown: `response_format: "markdown"` (API default is html); on spicrawl_scrape, `format: "markdown"`. - Check the site's status, not only the HTTP status: `X-Target-Status` header, or `status` in the JSON envelope (spicrawl_scrape with `format: "json"`). 200 is the page; 404/410 mean it does not exist; 403/429/503 mean the site refused, so escalate. - On an error, switch on `code`. Retry only when `retryable` is true, after `retry_after_seconds`. Read `diagnostics.hint` and change what it names first. Never retry ERR::REQUEST::*, ERR::AUTH::* or ERR::LIMIT::QUOTA_EXCEEDED. - Escalate one step at a time and stop at the first that works: plain fetch (1 credit) -> `js_render: true` (3) -> add the user's own `proxy` if they have one. Empty or skeleton content means render; ERR::UPSTREAM::CHALLENGE or a 403 target status means retry once, then the user's own proxy. - Set `max_cost` on every request to the price of the step you intend. - Keep the cache on (default). Set `cache: false` only for prices, stock or other live data. - Trim tokens with `main_content_only` (on by default for markdown), `include_tags`, `exclude_tags`. - For more than 20 URLs, use a batch job (spicrawl_batch_submit / POST /v1/batch). Batch items return html, markdown or text (spicrawl_batch_submit defaults to markdown, POST /v1/batch to html). Extraction, screenshots, actions and sessions are refused with a 400 before anything is charged: scrape those URLs one by one. - With the CLI, read stdout as JSON and branch on the exit code: 3 auth, 4 bad request, 5 limit, 6 site refused or failed, 7 proxy, 8 engine or extraction, 10 network. - Never print or commit SPICRAWL_API_KEY. Log `X-Request-Id` for failures.用
codex mcp list检查,或在会话中用/mcp检查。你应该能看到 25 个spicrawl_*工具。
或使用 CLI
Codex 在 shell 中运行,因此 spicrawl CLI 无需任何配置即可使用。它在管道输出时打印 JSON,并以稳定的退出码退出:
spicrawl scrape https://example.com/pricing --format markdown --max-cost 3 | jq -r .content在 Codex 云端,不要依赖 MCP 服务器。请使用 CLI 或普通 HTTP。把 SPICRAWL_API_KEY 设置为环境变量,而不是 secret,并在智能体的互联网访问中允许 api.spicrawl.com。
可以先试的第一个任务
在项目中启动 codex 并提问:
Use Spicrawl to read https://example.com/pricing as markdown. List each plan with its monthly price.
If the page comes back empty, retry with rendering.它能做什么
该服务器为智能体提供 25 个 spicrawl_* 工具。每次调用都在你的 API key 下运行,限制和积分与直接调用 API 相同。
- 读取一个页面:
spicrawl_scrape返回 Markdown(默认)、文本、HTML、JSON 或 PDF。 - 读取多个页面:
spicrawl_batch_submit最多可排入 10,000 个 URL。之后用spicrawl_batch_status和spicrawl_batch_results跟进。 - 登录后的页面:
spicrawl_session_create会在多次调用之间保留 cookie 和存储。 - 调试失败:
spicrawl_requests_list和spicrawl_request_get。 - 查看用量:
spicrawl_usage_summary及其他用量工具。这些工具需要具有read权限范围的 key。 - 查资料:
spicrawl_docs_search和spicrawl_docs_read用于搜索和阅读 Spicrawl 文档。
有一个工具 spicrawl_browser_connect_url 已列出但即将推出。在 spicrawl_scrape 上,渲染参数是 render,而不是 API 的 js_render。
须知
- 不支持爬取。 Spicrawl 不会跟随链接或查找页面。请把 URL 交给智能体。
- 每次请求的积分。 普通抓取 1 积分。JavaScript 渲染 3。完整浏览器渲染 8。
- 失败免费。 失败的请求费用为 0 积分。
- 缓存节省的是时间,而不是积分。 缓存命中的费用与存储它的那次获取相同。
- 为每次调用设置上限。 设置
max_cost后,可能超出预算的请求会在运行前被拒绝。 - 即将推出: 托管代理、隐身模式、远程浏览器,以及基于自然语言提示词的 AI 提取。目前你可以自带代理。
常见问题
Codex 把服务器存储在哪里?
在 ~/.codex/config.toml 中。若只想在一个项目中使用,请把同样的表放在 .codex/config.toml 中。Codex 只在受信任的项目中读取项目配置。
Codex 可以用 CLI 代替 MCP 吗?
可以。Codex 在 shell 中运行,因此可以运行 spicrawl scrape URL --format markdown --max-cost 3。CLI 通过管道输出时会打印 JSON,并以稳定的退出码退出。
它能在 Codex 云端使用吗?
不要指望那里能用 MCP 服务器。请使用 CLI 或普通 HTTP。将 SPICRAWL_API_KEY 设置为环境变量(而不是 secret),并在智能体的互联网访问中允许 api.spicrawl.com。
服务器为什么返回 401?
启动 codex 的 shell 中没有设置 SPICRAWL_API_KEY。请导出它并启动新的会话。
每个页面要多少钱?
普通抓取 1 积分,JavaScript 渲染 3,完整浏览器渲染 8。失败的请求为 0。缓存命中的费用与存入该缓存的那次抓取相同。让智能体在每次请求上设置 max_cost,这样花费就不会超出你的预期。