Spicrawl ora funziona con OpenAI Agents SDK, LangChain, Codex, Claude Code e altri.Vedi le integrazioni
Vai al contenuto

Web scraping in VS Code con Copilot

Aggiungi il server MCP di Spicrawl a VS Code. Copilot in modalità agent potrà così leggere le pagine web come Markdown pulito.

Configuralo

Tre passaggi danno a Copilot gli strumenti, il know-how per scrivere codice Spicrawl e le regole per usarli entrambi. spicrawl init --client vscode fa per te i primi due.

  1. Crea .vscode/mcp.json nel progetto. VS Code usa la chiave servers, non mcpServers. L’input password fa chiedere la chiave a VS Code una sola volta e la salva, quindi il file si può committare senza rischi:

    .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. Esegui MCP: List Servers dalla Command Palette e avvia spicrawl. Inserisci la chiave quando richiesto.

  3. Installa la skill e fai commit:

    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. Salvalo come .github/copilot-instructions.md, oppure aggiungilo al file che hai già:

    .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. Apri la vista Chat, passa alla modalità Agente e apri il selettore degli strumenti. spicrawl elenca 25 strumenti spicrawl_*.

La CLI di Copilot e l’agente cloud di Copilot leggono ciascuno la propria configurazione MCP. La pagina della documentazione le copre entrambe.

Un primo task da provare

Apri Copilot Chat in modalità Agent e chiedi:

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.

L’agente dovrebbe richiamare spicrawl_scrape con format: "markdown". Dovrebbe aggiungere render: true solo se il primo risultato è vuoto.

Cosa può fare

Il server offre all’agente 25 strumenti spicrawl_*. Ogni chiamata viene eseguita con la tua chiave API, con gli stessi limiti e crediti di una chiamata diretta all’API.

  • Leggi una pagina: spicrawl_scrape restituisce Markdown (predefinito), testo, HTML, JSON o PDF.
  • Leggi molte pagine: spicrawl_batch_submit mette in coda fino a 10.000 URL. Poi usa spicrawl_batch_status e spicrawl_batch_results.
  • Pagine dietro un login: spicrawl_session_create mantiene cookie e storage tra una chiamata e l’altra.
  • Fai il debug di un errore: spicrawl_requests_list e spicrawl_request_get.
  • Controlla l’utilizzo: spicrawl_usage_summary e gli altri strumenti di utilizzo. Richiedono una chiave con lo scope read.
  • Cerca informazioni: spicrawl_docs_search e spicrawl_docs_read cercano e leggono nella documentazione di Spicrawl.

Uno strumento, spicrawl_browser_connect_url, è elencato ma in arrivo. Su spicrawl_scrape, l’argomento di rendering è render, non js_render come nell’API.

Da sapere

  • Nessun crawling. Spicrawl non segue link né trova pagine. Dai all’agente gli URL.
  • Crediti per richiesta. Un fetch semplice costa 1 credito. Il rendering JavaScript 3. Il rendering con browser completo 8.
  • I fallimenti sono gratuiti. Una richiesta fallita costa 0 crediti.
  • La cache fa risparmiare tempo, non crediti. La cache fa risparmiare tempo, non crediti.
  • Limita ogni chiamata. Imposta max_cost, e una richiesta che potrebbe costare di più viene rifiutata prima di essere eseguita.
  • In arrivo: proxy gestiti, modalità stealth, un browser remoto ed estrazione con AI da un prompt in linguaggio naturale. Oggi puoi usare il tuo proxy.

Domande frequenti

Perché VS Code usa "servers" e non "mcpServers"?

Questo è il formato di VS Code. Usa la chiave servers in .vscode/mcp.json, come nell’esempio in questa pagina.

Dove viene conservata la mia chiave?

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.

Funziona con la Copilot CLI e con l’agente cloud?

Sì, ma ciascuno legge la propria configurazione MCP. La Copilot CLI usa copilot mcp add. L’agente cloud viene configurato da un admin del repository in Settings → Copilot → MCP servers. La pagina della documentazione copre entrambi.

Cosa scrive spicrawl init --client vscode?

Scrive .vscode/mcp.json e la skill in .github/skills/spicrawl/SKILL.md. Non scrive il file di istruzioni né la configurazione della Copilot CLI o dell’agente cloud.

Quanto costa ogni pagina?

Un fetch semplice costa 1 credito, il rendering JavaScript 3 e il rendering con browser completo 8. Le richieste fallite costano 0. Un cache hit costa quanto il fetch che l’ha salvato. Chiedi all’agente di impostare max_cost su ogni richiesta così non spende mai più del previsto.