Spicrawl nay hoạt động với OpenAI Agents SDK, LangChain, Codex, Claude Code và nhiều hơn nữa.Xem các tích hợp
Chuyển đến nội dung

Web scraping trong Claude Code

Thêm MCP server Spicrawl vào Claude Code. Claude khi đó có thể đọc trang web dưới dạng Markdown sạch.

Thiết lập

Ba bước giúp Claude Code có các tool, kiến thức để viết code Spicrawl và các quy tắc để dùng cả hai. Hoặc làm cả ba bằng spicrawl init --client claude.

  1. Đặt API key của bạn:

    bash
    export SPICRAWL_API_KEY=spicrawl_live_...   # add to your shell profile
  2. Thêm MCP server. Shell của bạn điền key, và Claude Code lưu nó trong ~/.claude.json, bên ngoài repository. Thêm --scope user để dùng trong mọi project.

    bash
    claude mcp add --transport http spicrawl https://mcp.spicrawl.com/mcp \
      --header "Authorization: Bearer $SPICRAWL_API_KEY"

    Với một nhóm, hãy commit .mcp.json ở thư mục gốc của project. Claude Code đọc key riêng của từng người từ môi trường của họ:

    .mcp.json
    {
      "mcpServers": {
        "spicrawl": {
          "type": "http",
          "url": "https://mcp.spicrawl.com/mcp",
          "headers": { "Authorization": "Bearer ${SPICRAWL_API_KEY}" }
        }
      }
    }
  3. Cài skill. Claude nạp nó khi một tác vụ liên quan đến dữ liệu web, hoặc khi bạn gõ /spicrawl:

    bash
    mkdir -p .claude/skills/spicrawl
    curl -fsSL https://app.spicrawl.com/skill.md -o .claude/skills/spicrawl/SKILL.md
  4. Dán phần này vào CLAUDE.md ở thư mục gốc của project:

    CLAUDE.md
    ## Web data (Spicrawl)
    
    Use Spicrawl to read web pages: the spicrawl_* MCP tools in chat, 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.
    - Never print or commit SPICRAWL_API_KEY. Log `X-Request-Id` for failures.
  5. Kiểm tra bằng claude mcp list, hoặc /mcp trong một session. Bạn sẽ thấy 25 tool spicrawl_*.

Thích plugin hơn? Nó gói sẵn MCP server và skill, nên bạn có thể bỏ qua bước 2 và 3. Claude Code hỏi key của bạn khi bạn bật nó:

bash
claude plugin marketplace add OfficialSpicrawl/agent-plugins
claude plugin install spicrawl@spicrawl-plugins

Một tác vụ đầu tiên để thử

Khởi động claude trong project và hỏi:

prompt
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. Tell me how many credits it cost.

Claude gọi spicrawl_scrape. Để báo cáo chi phí, nó cần format: "json", vì envelope đó chứa credits. Hướng dẫn đầy đủ nằm trong cách scrape một trang web với Claude Code.

Nó làm được gì

Server cung cấp cho agent 25 tool spicrawl_*. Mỗi lệnh gọi chạy dưới API key của bạn, với cùng giới hạn và credit như một lệnh gọi API trực tiếp.

  • Đọc một trang: spicrawl_scrape trả về Markdown (mặc định), text, HTML, JSON hoặc PDF.
  • Đọc nhiều trang: spicrawl_batch_submit xếp hàng tới 10,000 URL. Sau đó dùng spicrawl_batch_status và spicrawl_batch_results.
  • Trang sau màn hình đăng nhập: spicrawl_session_create giữ cookie và bộ nhớ lưu trữ giữa các lệnh gọi.
  • Gỡ lỗi một sự cố: spicrawl_requests_list và spicrawl_request_get.
  • Kiểm tra mức dùng: spicrawl_usage_summary và các tool về mức dùng khác. Các tool này cần key có scope read.
  • Tra cứu: spicrawl_docs_search và spicrawl_docs_read tìm kiếm và đọc tài liệu Spicrawl.

Có một tool, spicrawl_browser_connect_url, được liệt kê nhưng sắp ra mắt. Trên spicrawl_scrape, đối số render là render, không phải js_render của API.

Nên biết

  • Không crawl. Spicrawl không đi theo liên kết hay tự tìm trang. Hãy đưa các URL cho agent.
  • Credit cho mỗi request. Một lần fetch thường là 1 credit. Render JavaScript là 3. Render bằng trình duyệt đầy đủ là 8.
  • Thất bại là miễn phí. Request thất bại tốn 0 credit.
  • Cache tiết kiệm thời gian, không tiết kiệm credit. Một lần trúng cache tốn bằng lần fetch đã lưu nó.
  • Giới hạn từng lệnh gọi. Đặt max_cost, và một request có thể tốn nhiều hơn sẽ bị từ chối trước khi chạy.
  • Sắp ra mắt: proxy được quản lý, chế độ stealth, trình duyệt từ xa và trích xuất AI từ một prompt bằng ngôn ngữ thường. Hiện tại bạn có thể dùng proxy của riêng mình.

Câu hỏi thường gặp

Làm sao để thêm Spicrawl vào Claude Code?

Export SPICRAWL_API_KEY, rồi chạy claude mcp add --transport http spicrawl https://mcp.spicrawl.com/mcp --header "Authorization: Bearer $SPICRAWL_API_KEY". Kiểm tra bằng claude mcp list.

Làm sao để chia sẻ thiết lập với team của tôi?

Commit .mcp.json at the project root with the header "Bearer ${SPICRAWL_API_KEY}". Claude Code fills in each person’s own key from their environment when it starts.

Có plugin Claude Code không?

Có. Chạy claude plugin marketplace add OfficialSpicrawl/agent-plugins, rồi claude plugin install spicrawl@spicrawl-plugins. Nó gói sẵn MCP server và skill, và hỏi key của bạn khi bạn bật nó.

Tại sao Claude gặp lỗi "unknown argument" với js_render?

Với tool spicrawl_scrape, đối số được gọi là render. js_render là tên trong API HTTP.

Mỗi trang tốn bao nhiêu?

Một lần fetch thường tốn 1 credit, render JavaScript 3 và render bằng trình duyệt đầy đủ 8. Request thất bại tốn 0. Cache hit tốn bằng với lần fetch đã lưu nó. Hãy yêu cầu agent đặt max_cost cho mỗi request để nó không bao giờ tiêu nhiều hơn bạn dự kiến.