使用 OpenClaw Web Tools 讓你的 AI 具備聯網搜尋與網頁擷取能力
開發時最煩人的就是 AI 沒辦法存取即時資訊。當你需要它分析最新的 API 文件,或者抓取某個網站的內容時,手動複製貼上簡直是浪費時間。如果你的 AI 助手能自己上網搜尋並抓取重點,開發流程會順暢很多。
OpenClaw 內建了兩個輕量級的 Web 工具:web_search 用於聯網搜尋,web_fetch 則負責將網頁內容轉為乾淨的 Markdown 或純文字。要注意的是,這兩個工具都不是瀏覽器自動化,如果遇到需要執行 JavaScript 或登入的網站,請改用 Browser tool。
需要準備的東西
Section titled “需要準備的東西”- OpenClaw Gateway 環境
- 至少一組支援的搜尋 API Key(例如 Brave 或 Perplexity)
- 取得 API Key:到 Brave Search API 或 Perplexity 建立帳號並產生 Key。
- 快速配置:在你的終端機執行
openclaw configure --section web,依照提示貼上你的 Key 並選擇 Provider。 - 開始使用:現在你的 AI 已經可以使用
web_search來尋找最新資訊了。
選擇搜尋 Provider
Section titled “選擇搜尋 Provider”| Provider | Pros | Cons | API Key |
|---|---|---|---|
| Perplexity Search API | 速度快、結果結構化;支援網域、語言、地區與新鮮度過濾;包含內容擷取 | — | PERPLEXITY_API_KEY |
| Brave Search API | 速度快、結果結構化 | 過濾選項較少;適用 AI 使用條款 | BRAVE_API_KEY |
| Gemini | Google Search grounding,AI 綜合彙整 | 需要 Gemini API key | GEMINI_API_KEY |
| Grok | xAI 聯網回應 | 需要 xAI API key | XAI_API_KEY |
| Kimi | Moonshot 聯網搜尋能力 | 需要 Moonshot API key | KIMI_API_KEY / MOONSHOT_API_KEY |
自動偵測機制
Section titled “自動偵測機制”如果你沒有明確設定 provider,OpenClaw 會依照以下順序檢查環境變數或配置,自動決定使用的 Provider:
- Brave —
BRAVE_API_KEY - Gemini —
GEMINI_API_KEY - Kimi —
KIMI_API_KEY或MOONSHOT_API_KEY - Perplexity —
PERPLEXITY_API_KEY - Grok —
XAI_API_KEY
如果找不到任何 Key,系統會預設回退到 Brave 並提示你缺少 Key。
設定 Web Search
Section titled “設定 Web Search”你可以使用 openclaw configure --section web 來儲存 Key,或者直接設定環境變數。
Perplexity Search:
{ tools: { web: { search: { enabled: true, provider: "perplexity", perplexity: { apiKey: "pplx-...", // 如果已設定 PERPLEXITY_API_KEY 則可省略 }, }, }, },}Brave Search:
{ tools: { web: { search: { enabled: true, provider: "brave", apiKey: "YOUR_BRAVE_API_KEY", // 如果已設定 BRAVE_API_KEY 則可省略 }, }, },}使用 Gemini (Google Search grounding)
Section titled “使用 Gemini (Google Search grounding)”Gemini 模型支援內建的 Google Search grounding,能提供帶有引用來源的 AI 彙整答案。
{ tools: { web: { search: { provider: "gemini", gemini: { apiKey: "AIza...", model: "gemini-2.5-flash", // 預設模型 }, }, }, },}web_search 工具參數
Section titled “web_search 工具參數”你可以透過參數精確控制搜尋結果:
| 參數 | 說明 |
|---|---|
query | 搜尋字串 (必填) |
count | 回傳結果數量 (1-10, 預設 5) |
country | 2 位 ISO 國家代碼 (如 “US”, “TW”) |
language | ISO 639-1 語言代碼 (如 “en”, “zh”) |
freshness | 時間過濾:day, week, month, year |
domain_filter | 網域白名單/黑名單陣列 (僅限 Perplexity) |
程式碼範例:
// 搜尋過去一週內的內容await web_search({ query: "TMBG interview", freshness: "week",});
// 指定網域過濾 (僅限 Perplexity)await web_search({ query: "climate research", domain_filter: ["nature.com", "science.org", ".edu"],});web_fetch 網頁擷取
Section titled “web_fetch 網頁擷取”web_fetch 預設是啟用的,它會抓取 URL 並提取出可讀內容。它會先嘗試使用 Readability 進行內容提取,如果失敗則會嘗試你配置的 Firecrawl。
web_fetch 配置
Section titled “web_fetch 配置”{ tools: { web: { fetch: { enabled: true, maxChars: 50000, timeoutSeconds: 30, cacheTtlMinutes: 15, firecrawl: { enabled: true, apiKey: "FIRECRAWL_API_KEY_HERE", }, }, }, },}web_fetch會阻擋私有或內部網路的 Hostname。- 回傳結果會快取 15 分鐘以減少重複抓取。
- 如果網頁內容太大,會根據
maxChars進行截斷。 - 遇到大量使用 JavaScript 渲染的網站,建議改用 Browser tool。
- 搜尋沒反應:檢查
tools.web.search.enabled是否被設為false,並確認你的 API Key 是否有效。 - 擷取內容不完整:這是因為
web_fetch僅抓取靜態 HTML。如果網站內容是動態載入的,擷取結果可能只有空白或讀取畫面。
如果你在設定上遇到任何困難,可以詢問 AI Setup Assistant 獲取即時協助。
- Browser tool — 處理需要 JavaScript 的複雜網站
- Firecrawl — 設定進階爬蟲服務
- Perplexity Search setup — 深入了解 Perplexity 配置
- Brave Search setup — 深入了解 Brave 配置
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。