File contents 🕷️ web-scraper(增强版)
✅ 状态 :增强版已上线,功能完整。
功能
核心功能
HTTP 请求 :GET/POST 请求,支持自定义 headers
会话管理 :Cookie 持久化,会话复用
多模式提取 :
CSS 选择器提取
XPath 表达式提取
正则表达式提取
并发抓取 :多 URL 并发抓取(3个并发)
反爬虫增强 :
User-Agent 轮换
请求延迟随机化
代理支持(预留接口)
元数据提取 :自动提取页面标题、描述、链接等
输出格式
JSON 结构化数据
保存到 __LEGACY_HOME__/.openclaw/output/scraping/
会话保存到 __LEGACY_HOME__/.openclaw/sessions/web-scraper/
使用方法
通过技能调用
用户说"抓取网页"或"提取数据"时自动触发。
命令行接口
# 健康检查
python3 scripts/scraper_cli.py --check
# 基础抓取
python3 scripts/scraper_cli.py --url "https://example.com" --css '{"title": "h1"}'
# 使用会话
python3 scripts/scraper_cli.py --url "https://example.com" --session "my_session"
# XPath 提取
python3 scripts/scraper_cli.py --url "https://example.com" --xpath '{"title": "//h1/text()"}'
# 正则提取
python3 scripts/scraper_cli.py --url "https://example.com" --regex '{"emails": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"}'
# 并发抓取
python3 scripts/scraper_cli.py --urls "https://example1.com" "https://example2.com" --concurrent
# 指定输出文件
python3 scripts/scraper_cli.py --url "https://example.com" --output "result.json"
# 会话管理
python3 scripts/scraper_cli.py --list-sessions
python3 scripts/scraper_cli.py --clear-session --session "old_session"
Python API
from scraper_enhanced import scrape_enhanced, SessionManager, DataExtractor
# 简单抓取
result = scrape_enhanced(
url="https://example.com",
selectors={"title": "h1", "content": ".article"},
session_name="my_session"
)
# 使用会话管理器
session = SessionManager("test_session")
fetch_result = session.fetch("https://example.com")
# 使用数据提取器
extractor = DataExtractor(fetch_result["content"])
css_data = extractor.extract_css({"title": "h1"})
xpath_data = extractor.extract_xpath({"title": "//h1/text()"})
技术实现
基于 requests + BeautifulSoup4 + lxml 实现,提供完整的抓取解决方案。
高级功能
会话持久化 :自动保存和加载 Cookie
智能重试 :网络错误自动重试
延迟控制 :随机延迟避免封禁
错误处理 :详细的错误信息和恢复建议
性能监控 :记录抓取时间和大小
限制
不支持 JavaScript 渲染页面(需要 browser-pilot)
复杂反爬虫网站可能需要额外配置
未来计划
集成 Playwright 支持 JavaScript 页面
分布式抓取支持
智能代理轮换系统
1 --- 2 name: web-scraper 3 description: Web Scraper 4 --- 5 6 # 🕷️ web-scraper(增强版) 7 8 ✅ **状态**:增强版已上线,功能完整。 9 10 ## 功能 11 12 ### 核心功能 13 1. **HTTP 请求**:GET/POST 请求,支持自定义 headers 14 2. **会话管理**:Cookie 持久化,会话复用 15 3. **多模式提取**: 16 - CSS 选择器提取 17 - XPath 表达式提取 18 - 正则表达式提取 19 4. **并发抓取**:多 URL 并发抓取(3个并发) 20 5. **反爬虫增强**: 21 - User-Agent 轮换 22 - 请求延迟随机化 23 - 代理支持(预留接口) 24 6. **元数据提取**:自动提取页面标题、描述、链接等 25 26 ### 输出格式 27 - JSON 结构化数据 28 - 保存到 `__LEGACY_HOME__/.openclaw/output/scraping/` 29 - 会话保存到 `__LEGACY_HOME__/.openclaw/sessions/web-scraper/` 30 31 ## 使用方法 32 33 ### 通过技能调用 34 用户说"抓取网页"或"提取数据"时自动触发。 35 36 ### 命令行接口 37 ```bash 38 # 健康检查 39 python3 scripts/scraper_cli.py --check 40 41 # 基础抓取 42 python3 scripts/scraper_cli.py --url "https://example.com" --css '{"title": "h1"}' 43 44 # 使用会话 45 python3 scripts/scraper_cli.py --url "https://example.com" --session "my_session" 46 47 # XPath 提取 48 python3 scripts/scraper_cli.py --url "https://example.com" --xpath '{"title": "//h1/text()"}' 49 50 # 正则提取 51 python3 scripts/scraper_cli.py --url "https://example.com" --regex '{"emails": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"}' 52 53 # 并发抓取 54 python3 scripts/scraper_cli.py --urls "https://example1.com" "https://example2.com" --concurrent 55 56 # 指定输出文件 57 python3 scripts/scraper_cli.py --url "https://example.com" --output "result.json" 58 59 # 会话管理 60 python3 scripts/scraper_cli.py --list-sessions 61 python3 scripts/scraper_cli.py --clear-session --session "old_session" 62 ``` 63 64 ### Python API 65 ```python 66 from scraper_enhanced import scrape_enhanced, SessionManager, DataExtractor 67 68 # 简单抓取 69 result = scrape_enhanced( 70 url="https://example.com", 71 selectors={"title": "h1", "content": ".article"}, 72 session_name="my_session" 73 ) 74 75 # 使用会话管理器 76 session = SessionManager("test_session") 77 fetch_result = session.fetch("https://example.com") 78 79 # 使用数据提取器 80 extractor = DataExtractor(fetch_result["content"]) 81 css_data = extractor.extract_css({"title": "h1"}) 82 xpath_data = extractor.extract_xpath({"title": "//h1/text()"}) 83 ``` 84 85 ## 技术实现 86 87 基于 `requests` + `BeautifulSoup4` + `lxml` 实现,提供完整的抓取解决方案。 88 89 ## 高级功能 90 91 1. **会话持久化**:自动保存和加载 Cookie 92 2. **智能重试**:网络错误自动重试 93 3. **延迟控制**:随机延迟避免封禁 94 4. **错误处理**:详细的错误信息和恢复建议 95 5. **性能监控**:记录抓取时间和大小 96 97 ## 限制 98 99 1. 不支持 JavaScript 渲染页面(需要 browser-pilot) 100 2. 复杂反爬虫网站可能需要额外配置 101 102 ## 未来计划 103 104 - 集成 Playwright 支持 JavaScript 页面 105 - 分布式抓取支持 106 - 智能代理轮换系统
xyva-yuangui/XyvaClaw/tree/main/config-base/workspace/skills/web-scraper commit 5ca577dba8
Frequently asked questions How do I install the Web Scraper skill? Run npx skillmds@latest add xyva-yuangui/web-scraper in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Web Scraper skill do? Web Scraper It is listed under Coding & Dev Tools on SkillMD.
Is Web Scraper safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Web Scraper? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Web Scraper free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Web Scraper? xyva-yuangui (@xyva-yuangui) published this skill. Their other Agent Skills are listed on their SkillMD profile.