Codex でのウェブスクレイピング
Codex に Spicrawl MCP サーバーを追加します。Codex はウェブページをクリーンな Markdown として読めるようになります。
セットアップする
3 つの手順で、Codex にツール、Spicrawl のコードを書くための知識、両方を使うためのルールを与えます。3 つすべてを spicrawl init --client codex で行うこともできます。
API キーを設定します:
bashexport SPICRAWL_API_KEY=spicrawl_live_... # add to your shell profileMCP サーバーを追加します。Codex は接続のたびに
SPICRAWL_API_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"1 つのプロジェクトだけの場合は、テーブルを
.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を実行して確認してください。spicrawl_*ツールが 25 個表示されるはずです。
または CLI を使う
Codex はシェルで動くため、spicrawl CLI は設定なしで動作します。パイプされると JSON を出力し、安定した終了コードで終了します:
spicrawl scrape https://example.com/pricing --format markdown --max-cost 3 | jq -r .contentCodex cloud では、MCP サーバーを当てにしないでください。CLI か通常の HTTP を使います。SPICRAWL_API_KEY は、シークレットではなく環境変数として設定し、エージェントのインターネットアクセスで 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.できること
このサーバーは、エージェントに spicrawl_* ツールを 25 個提供します。各呼び出しはお客様の API キーのもとで実行され、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スコープを持つキーが必要です。 - 調べる:
spicrawl_docs_searchとspicrawl_docs_readで Spicrawl のドキュメントを検索して読めます。
ツール spicrawl_browser_connect_url は一覧にありますが、近日公開です。spicrawl_scrape では、レンダリングの引数は API の js_render ではなく render です。
知っておくべきこと
- クロールはありません。 Spicrawl はリンクをたどったり、ページを探したりしません。エージェントに URL を渡してください。
- リクエストごとのクレジット。 通常のフェッチは 1 クレジット、JavaScript レンダリングは 3、フルブラウザレンダリングは 8 です。
- 失敗は無料です。 失敗したリクエストは 0 クレジットです。
- キャッシュで節約できるのは時間であり、クレジットではありません。 キャッシュヒットの料金は、それを保存したフェッチと同じです。
- 呼び出しごとに上限を設けてください。
max_costを設定すると、より高くなる可能性のあるリクエストは実行前に拒否されます。 - 近日公開: マネージドプロキシ、ステルスモード、リモートブラウザ、自然な言葉で書いたプロンプトからの AI 抽出。現時点では、ご自身のプロキシを使えます。
よくある質問
Codex はサーバーをどこに保存しますか?
~/.codex/config.toml に記述します。一つのプロジェクトだけで使う場合は、同じテーブルを .codex/config.toml に置いてください。Codex はプロジェクト設定を信頼済みプロジェクトでのみ読み込みます。
Codex では MCP の代わりに CLI を使えますか?
はい。Codex はシェルで動作するため、spicrawl scrape URL --format markdown --max-cost 3 を実行できます。CLI は、パイプされると JSON を出力し、安定した終了コードで終了します。
Codex クラウドで動作しますか?
そこでは MCP サーバーを当てにしないでください。CLI か通常の HTTP を使います。SPICRAWL_API_KEY を環境変数として(シークレットではなく)設定し、エージェントのインターネットアクセスで api.spicrawl.com を許可してください。
サーバーが 401 を返すのはなぜですか?
codex を起動したシェルで SPICRAWL_API_KEY が設定されていませんでした。エクスポートしてから、新しいセッションを開始してください。
1 ページの料金はいくらですか?
通常のフェッチは 1 クレジット、JavaScript レンダリングは 3、フルブラウザレンダリングは 8 です。失敗したリクエストは 0 クレジットです。キャッシュヒットは、それを保存したフェッチと同じ料金です。エージェントに各リクエストで max_cost を設定するよう指示すれば、想定以上の出費を防げます。