Web scraping trong Cursor
Thêm MCP server Spicrawl vào Cursor. Agent của nó khi đó có thể đọc trang web dưới dạng Markdown sạch.
Thiết lập
Ba bước giúp agent của Cursor 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 cursor.
Đặt API key của bạn trong môi trường mà Cursor khởi động từ đó:
bashexport SPICRAWL_API_KEY=spicrawl_live_... # add to your shell profile, then restart CursorTrên macOS, các ứng dụng khởi động từ Dock không thấy profile shell của bạn. Hãy khởi động Cursor từ terminal bằng
cursor ..Thêm server vào
.cursor/mcp.json(hoặc~/.cursor/mcp.jsoncho mọi project). Cursor tự điền key, nên tệp này có thể commit an toàn:.cursor/mcp.json{ "mcpServers": { "spicrawl": { "url": "https://mcp.spicrawl.com/mcp", "headers": { "Authorization": "Bearer ${env:SPICRAWL_API_KEY}" } } } }Cài skill:
bashspicrawl skill install --client cursor # Without the CLI: mkdir -p .cursor/skills/spicrawl curl -fsSL https://app.spicrawl.com/skill.md -o .cursor/skills/spicrawl/SKILL.mdLưu rule này thành
.cursor/rules/spicrawl.mdc. Agent đọc nó khi một tác vụ liên quan đến dữ liệu web. ĐặtalwaysApply: trueđể đưa nó vào mọi cuộc trò chuyện..cursor/rules/spicrawl.mdc--- description: Fetching, scraping or extracting data from web pages with Spicrawl alwaysApply: false --- # 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.Mở Cursor Settings → MCP. Kiểm tra rằng
spicrawlđang bật và liệt kê 25 toolspicrawl_*.
Một tác vụ đầu tiên để thử
Mở agent ở chế độ Agent và hỏi:
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.
Cloud agent
Các cloud agent của Cursor chạy trong một VM từ xa, nên chúng không thấy key trong shell của bạn. Hãy thêm server trong dashboard Cursor với URL https://mcp.spicrawl.com/mcp và header Authorization: Bearer cùng key của bạn. Đừng commit key. Skill và rule lấy từ repository.
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_scrapetrả về Markdown (mặc định), text, HTML, JSON hoặc PDF. - Đọc nhiều trang:
spicrawl_batch_submitxếp hàng tới 10,000 URL. Sau đó dùngspicrawl_batch_statusvàspicrawl_batch_results. - Trang sau màn hình đăng nhập:
spicrawl_session_creategiữ cookie và bộ nhớ lưu trữ giữa các lệnh gọi. - Gỡ lỗi một sự cố:
spicrawl_requests_listvàspicrawl_request_get. - Kiểm tra mức dùng:
spicrawl_usage_summaryvà các tool về mức dùng khác. Các tool này cần key có scoperead. - Tra cứu:
spicrawl_docs_searchvàspicrawl_docs_readtì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
Commit .cursor/mcp.json có an toàn không?
Yes, if you use ${env:SPICRAWL_API_KEY} in the header. Cursor replaces it with the value from your environment, so the file holds no key.
Tại sao server hiện lỗi 401?
SPICRAWL_API_KEY chưa được đặt khi Cursor khởi động. Trên macOS, các ứng dụng khởi động từ Dock không thấy shell profile của bạn. Hãy khởi động Cursor từ terminal bằng cursor . thay thế.
Nó có hoạt động với các cloud agent của Cursor không?
Có. Thêm server trong dashboard Cursor với URL và header Authorization của bạn. Đừng commit key. Skill và quy tắc được đọc từ repository.
Server được liệt kê nhưng không có tool nào. Giờ làm gì?
Tắt rồi bật lại nó trong Cursor Settings → MCP, rồi mở một cuộc trò chuyện mới.
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.