跳轉到主要內容

Documentation Index

Fetch the complete documentation index at: https://docs2.openclaw.ai/llms.txt

Use this file to discover all available pages before exploring further.

web_fetch 工具會執行一般 HTTP GET,並擷取可讀內容 (將 HTML 轉為 markdown 或文字)。它不會執行 JavaScript。 對於大量使用 JS 的網站或受登入保護的頁面,請改用 網頁瀏覽器

快速開始

web_fetch 預設啟用,不需要設定。Agent 可以立即呼叫它:
await web_fetch({ url: "https://example.com/article" });

工具參數

url
string
必填
要擷取的 URL。僅限 http(s)
extractMode
'markdown' | 'text'
預設值:"markdown"
主要內容擷取後的輸出格式。
maxChars
number
將輸出截斷為此字元數。

運作方式

1

Fetch

使用類似 Chrome 的 User-Agent 和 Accept-Language 標頭傳送 HTTP GET。阻擋私有/內部主機名稱,並重新檢查重新導向。
2

Extract

對 HTML 回應執行 Readability(主要內容擷取)。
3

Fallback (optional)

如果 Readability 失敗且已設定 Firecrawl,會透過 Firecrawl API 以繞過機器人防護模式重試。
4

Cache

結果會快取 15 分鐘(可設定),以減少重複擷取相同 URL。

設定

{
  tools: {
    web: {
      fetch: {
        enabled: true, // default: true
        provider: "firecrawl", // optional; omit for auto-detect
        maxChars: 50000, // max output chars
        maxCharsCap: 50000, // hard cap for maxChars param
        maxResponseBytes: 2000000, // max download size before truncation
        timeoutSeconds: 30,
        cacheTtlMinutes: 15,
        maxRedirects: 3,
        useTrustedEnvProxy: false, // let a trusted HTTP(S) env proxy resolve DNS
        readability: true, // use Readability extraction
        userAgent: "Mozilla/5.0 ...", // override User-Agent
        ssrfPolicy: {
          allowRfc2544BenchmarkRange: true, // opt-in for trusted fake-IP proxies using 198.18.0.0/15
          allowIpv6UniqueLocalRange: true, // opt-in for trusted fake-IP proxies using fc00::/7
        },
      },
    },
  },
}

Firecrawl 後備

如果 Readability 擷取失敗,web_fetch 可以後備使用 Firecrawl 來繞過機器人防護並取得更好的擷取效果:
{
  tools: {
    web: {
      fetch: {
        provider: "firecrawl", // optional; omit for auto-detect from available credentials
      },
    },
  },
  plugins: {
    entries: {
      firecrawl: {
        enabled: true,
        config: {
          webFetch: {
            apiKey: "fc-...", // optional if FIRECRAWL_API_KEY is set
            baseUrl: "https://api.firecrawl.dev",
            onlyMainContent: true,
            maxAgeMs: 86400000, // cache duration (1 day)
            timeoutSeconds: 60,
          },
        },
      },
    },
  },
}
plugins.entries.firecrawl.config.webFetch.apiKey 支援 SecretRef 物件。 舊版 tools.web.fetch.firecrawl.* 設定會由 openclaw doctor --fix 自動遷移。
如果 Firecrawl 已啟用,且其 SecretRef 未解析,又沒有 FIRECRAWL_API_KEY 環境變數後備,Gateway 啟動會快速失敗。
Firecrawl baseUrl 覆寫會受到鎖定限制:託管流量使用 https://api.firecrawl.dev;自架覆寫必須指向私有或 內部端點,而且只有這些私有目標才接受 http://
目前的執行階段行為:
  • tools.web.fetch.provider 會明確選取擷取後備提供者。
  • 如果省略 provider,OpenClaw 會從可用憑證中自動偵測第一個就緒的網頁擷取 提供者。非沙箱化的 web_fetch 可以使用已安裝、宣告 contracts.webFetchProviders 並在執行階段註冊相符提供者的 plugins。 目前內建提供者是 Firecrawl。
  • 沙箱化的 web_fetch 呼叫仍限制為內建提供者。
  • 如果停用 Readability,web_fetch 會直接跳到選定的 提供者後備。如果沒有可用提供者,它會以封閉方式失敗。

受信任環境代理

如果你的部署需要讓 web_fetch 透過受信任的對外 HTTP(S) 代理,請設定 tools.web.fetch.useTrustedEnvProxy: true 在此模式中,OpenClaw 仍會在送出請求前套用基於主機名稱的 SSRF 檢查, 但會讓代理解析 DNS,而不是執行本機 DNS 釘選。只有在代理由操作員控制,且會在 DNS 解析後強制執行 對外政策時,才啟用此選項。
如果未設定 HTTP(S) 代理環境變數,或目標主機被 NO_PROXY 排除,web_fetch 會後備回使用本機 DNS 釘選的正常嚴格路徑。

限制與安全性

  • maxChars 會被限制在 tools.web.fetch.maxCharsCap
  • 回應本文會在剖析前被限制為 maxResponseBytes;過大的 回應會被截斷並附上警告
  • 私有/內部主機名稱會被阻擋
  • tools.web.fetch.ssrfPolicy.allowRfc2544BenchmarkRangetools.web.fetch.ssrfPolicy.allowIpv6UniqueLocalRange 是狹義的選擇加入, 用於受信任的假 IP 代理堆疊;除非你的代理擁有 這些合成範圍並強制執行自己的目的地政策,否則請保持未設定
  • 重新導向會被檢查,並受 maxRedirects 限制
  • useTrustedEnvProxy 是明確的選擇加入,且只應針對 操作員控制、並仍會在 DNS 解析後強制執行對外政策的代理啟用
  • web_fetch 是盡力而為的工具,有些網站需要使用網頁瀏覽器

工具設定檔

如果你使用工具設定檔或允許清單,請加入 web_fetchgroup:web
{
  tools: {
    allow: ["web_fetch"],
    // or: allow: ["group:web"]  (includes web_fetch, web_search, and x_search)
  },
}

相關

  • 網頁搜尋 — 使用多個提供者搜尋網路
  • 網頁瀏覽器 — 針對大量使用 JS 的網站進行完整瀏覽器自動化
  • Firecrawl — Firecrawl 搜尋與擷取工具