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 VS Code với Copilot

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

Thiết lập

Ba bước giúp Copilot có các tool, kiến thức để viết code Spicrawl và các quy tắc để dùng cả hai. spicrawl init --client vscode làm hai bước đầu cho bạn.

  1. Tạo .vscode/mcp.json trong project. VS Code dùng khóa servers, không phải mcpServers. Ô nhập mật khẩu khiến VS Code hỏi key của bạn một lần rồi lưu lại, nên tệp này có thể commit an toàn:

    .vscode/mcp.json
    {
      "inputs": [
        {
          "type": "promptString",
          "id": "spicrawl-api-key",
          "description": "Spicrawl API key",
          "password": true
        }
      ],
      "servers": {
        "spicrawl": {
          "type": "http",
          "url": "https://mcp.spicrawl.com/mcp",
          "headers": { "Authorization": "Bearer ${input:spicrawl-api-key}" }
        }
      }
    }
  2. Chạy MCP: List Servers từ Command Palette và khởi động spicrawl. Nhập key của bạn khi được hỏi.

  3. Cài skill, và commit nó:

    bash
    spicrawl skill install --client vscode
    
    # Without the CLI:
    mkdir -p .github/skills/spicrawl
    curl -fsSL https://app.spicrawl.com/skill.md -o .github/skills/spicrawl/SKILL.md
  4. Lưu thành .github/copilot-instructions.md, hoặc thêm vào tệp bạn đã có:

    .github/copilot-instructions.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. Mở giao diện Chat, chuyển sang chế độ Agent và mở bộ chọn tool. spicrawl liệt kê 25 tool spicrawl_*.

Copilot CLI và Copilot cloud agent mỗi bên đọc cấu hình MCP riêng. trang tài liệu bao gồm cả hai.

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

Mở Copilot Chat ở chế độ Agent 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.

Agent nên gọi spicrawl_scrape với format: "markdown". Nó chỉ nên thêm render: true nếu kết quả đầu tiên rỗng.

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

Tại sao VS Code dùng "servers" mà không phải "mcpServers"?

Đó là định dạng riêng của VS Code. Dùng key servers trong .vscode/mcp.json, như trong ví dụ trên trang này.

Key của tôi được lưu ở đâu?

The inputs entry with password: true makes VS Code ask for the key once and store it. The file only holds ${input:spicrawl-api-key}, so you can commit it.

Nó có hoạt động với Copilot CLI và cloud agent không?

Có, nhưng mỗi bên đọc cấu hình MCP riêng của mình. Copilot CLI dùng copilot mcp add. Cloud agent được một admin repository thiết lập trong Settings → Copilot → MCP servers. Trang tài liệu bao gồm cả hai.

spicrawl init --client vscode ghi gì?

Nó ghi .vscode/mcp.json và skill tại .github/skills/spicrawl/SKILL.md. Nó không ghi tệp hướng dẫn hay cấu hình Copilot CLI hoặc cloud agent.

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.