🕸️ OpenClaw 网页抓取技能完全指南

世界上有一种能力叫网页抓取——它让AI能够阅读整个互联网,就像你妈喊你回家吃饭一样简单。

📖 功能介绍

web_fetch是OpenClaw强大的内容提取工具:

  • 网页内容提取 - HTML转Markdown/Text
  • PDF解析 - 提取PDF文档内容
  • Office文档 - 支持doc/docx/ppt/pptx/xls/xlsx/csv
  • 电子书 - epub/mobi格式支持
  • 可配置输出 - 指定字符数限制

🚀 使用方法

1. 基础网页抓取

// 获取网页内容(Markdown格式)
web_fetch({
  url: "https://example.com/article",
  extractMode: "markdown"
})
// 返回提取的Markdown内容

2. 纯文本提取

// 获取纯文本
web_fetch({
  url: "https://news.example.com",
  extractMode: "text",
  maxChars: 5000
})

3. PDF内容提取

// 提取PDF文档
web_fetch({
  url: "https://example.com/document.pdf",
  extractMode: "markdown"
})

💡 最佳实践

  1. 合理设置maxChars - 大页面限制字符数避免超时
  2. 选择合适格式 - 需要格式用markdown,纯内容用text
  3. 处理动态内容 - 动态页面用browser工具
  4. 尊重robots.txt - 合法合规抓取

📝 代码示例

场景:新闻聚合

// 批量抓取新闻
async function aggregateNews(sources) {
  const news = []
  
  for (const source of sources) {
    try {
      const content = await web_fetch({
        url: source.url,
        extractMode: "markdown",
        maxChars: 3000
      })
      
      news.push({
        title: source.title,
        content: content,
        source: source.name
      })
    } catch (e) {
      console.error(`Failed to fetch ${source.url}:`, e)
    }
  }
  
  return news
}