← 技能商店

🟢 实验室验证开发工具
smart-web-scraper实战:一行命令从任何网页扒出结构化数据
smart-web-scraper技能实战教程:CSS选择器精准抓取、表格自动检测、多页爬取、JSON/CSV输出。附电商价格监控、竞品分析实战案例。
📋 实验室验证报告
smart-web-scraper实战:一行命令从任何网页扒出结构化数据
传统的爬虫开发流程繁琐:分析网页结构、编写选择器、处理分页、应对反爬机制……每个新网站都需要重写一套代码。smart-web-scraper改变了这个范式——它是OpenClaw生态中的技能,核心承诺只有一句话:一行命令,从任何网页提取结构化数据。
什么是smart-web-scraper?
smart-web-scraper结合了LLM的语义理解能力和传统爬虫技术,能够:自动理解网页内容的语义结构(无需手动指定CSS选择器)、将非结构化HTML转换为JSON/CSV/Markdown、处理JavaScript渲染的动态页面、智能处理分页和无限滚动、提取特定类型的数据(价格、日期、联系方式、表格等)。本质上:你告诉它"我要什么",它自己去找"在哪里"。
安装
openclaw skills install smart-web-scraper
openclaw skills list | grep smart-web-scraper
# 如需处理JS渲染页面:
pip install playwright
playwright install chromium
基本用法
openclaw run smart-web-scraper --url "https://example.com/products" --extract "产品名称、价格、描述"
就这一行。smart-web-scraper会抓取网页、用LLM理解页面结构、提取指定字段,并以JSON格式返回结果,包含total_items和pages_scraped等元数据。
指定输出格式
# CSV格式(适合数据分析)
openclaw run smart-web-scraper --url "..." --extract "品牌、型号、价格" --format csv --output data.csv
# Markdown格式(适合内容爬取)
openclaw run smart-web-scraper --url "https://docs.example.com" --extract "完整文档内容" --format markdown
处理JavaScript渲染的页面
# 基本JS渲染
openclaw run smart-web-scraper --url "https://spa-site.example.com" --js-render true --wait 2000 --extract "商品列表"
# 懒加载/无限滚动
openclaw run smart-web-scraper --url "..." --js-render true --scroll-to-bottom true --extract "帖子标题、作者、点赞数"
处理分页
# 自动分页
openclaw run smart-web-scraper --url "https://example.com/products?page=1" --auto-paginate true --max-pages 10 --extract "产品名称、价格"
# 手动指定URL模式
openclaw run smart-web-scraper --url-pattern "https://example.com/products?page={1..20}" --extract "产品信息"
在Python中集成
from openclaw.skills import SmartWebScraper
scraper = SmartWebScraper()
result = await scraper.scrape(
url="https://competitor.com/pricing",
extract=["plan_name", "price", "features"],
format="json"
)
for item in result.data:
print(f"Plan: {item['plan_name']}, Price: {item['price']}")
实战示例
监控竞品价格:遍历竞品网站列表,批量提取产品名称和价格,返回结构化对比数据。
新闻聚合:从多个新闻源提取标题、发布日期、作者、摘要,支持按话题过滤,按时间排序。
管道处理:
openclaw run smart-web-scraper --url "..." --extract "价格" --format json | python3 -c "
import json, sys
data = json.load(sys.stdin)
prices = [item['price'] for item in data['data']]
print(f'最低价: {min(prices)}, 最高价: {max(prices)}')
"
最佳实践
- 遵守robots.txt:smart-web-scraper默认检查robots.txt,遵守网站爬取规则
- 设置请求间隔:使用
--delay 2在请求之间添加延迟,避免对目标服务器造成压力 - 错误处理:生产环境使用
--retries 3参数添加重试逻辑 - 数据清洗:使用
--clean-output true启用自动数据清洗,去除噪声
结语
smart-web-scraper让AI Agent获得了真正"看懂网页"的能力。从一行命令到完整的数据流水线,它大大降低了在Agent工作流中集成网络数据的门槛。无论是监控竞品、聚合资讯,还是构建数据集,smart-web-scraper都能让你的Agent从互联网上获取所需的结构化信息。
⚙️ 安装与赋能
clawhub install smart-web-scraper-structured-data-extraction-tutorial安装后在你的 Agent 配置中启用此技能,重启 Agent 即可生效。