Price Monitor
Overview
Automated price and content monitoring skill using agent-browser. Tracks price changes, stock availability, and content updates on any website with configurable alerts and history logging.
Quick Start
CODEBLOCK0
Core Workflows
1. Single Product Price Check
Use case: Check current price of a specific product
CODEBLOCK1
2. Multi-Product Monitoring
Use case: Track prices across multiple products/competitors
Create a products.csv with URLs and price selectors:
CODEBLOCK2
Run monitoring script:
CODEBLOCK3
3. Stock/Inventory Alerts
Use case: Get notified when out-of-stock items become available
CODEBLOCK4
4. Price History Tracking
Use case: Build historical price data for analysis
Script automatically logs:
- - Timestamp
- Product name/URL
- Current price
- Stock status
Output: price-history.csv or JSON format
Scripts
monitor_prices.py
Main monitoring script that:
- - Reads product list from CSV
- Navigates to each URL
- Extracts price using CSS selector
- Logs results with timestamp
- Detects price changes
- Optional: Send alerts on significant changes
Usage:
CODEBLOCK5
Arguments:
- -
products.csv - Product list with URLs and selectors - INLINECODE3 - Percentage change to trigger alert (default: 10%)
Configuration
Product List Format (CSV)
CODEBLOCK6
Alert Options
- - Email alerts - Configure SMTP settings
- Discord webhook - Post to Discord channel
- File logging - Append to CSV/JSON
- Console output - Print changes to terminal
Best Practices
- 1. Rate limiting - Add delays between requests (30s+ recommended)
- Error handling - Handle page load failures gracefully
- Selector stability - Use stable CSS selectors, avoid dynamic classes
- Headless mode - Run browser in headless mode for automation
- Schedule wisely - Check prices during business hours for accuracy
Example: Daily Price Check Cron
CODEBLOCK7
Troubleshooting
- - Element not found: Re-run snapshot to get updated refs
- Price format issues: Adjust selector or parse with regex
- Page load timeout: Increase timeout or add wait condition
- Blocked by site: Add delays, rotate user agents, or use residential proxy
技能名称: price-monitor
详细描述:
价格监控器
概述
基于agent-browser的自动化价格与内容监控技能。可追踪任意网站的价格变动、库存状态及内容更新,支持可配置警报与历史记录。
快速开始
bash
监控产品价格
agent-browser open https://example.com/product/123
agent-browser snapshot -i
agent-browser get text @e1 # 获取价格元素
核心工作流
1. 单品价格检查
应用场景: 查询特定产品的当前价格
bash
导航至产品页面
agent-browser open
获取页面快照以定位价格元素
agent-browser snapshot -i
提取价格(使用快照中的对应引用)
agent-browser get text @e1
可选:保存至历史记录
echo $(date), $(price) >> price-history.csv
2. 多产品监控
应用场景: 追踪多个产品/竞品的价格变动
创建包含URL和价格选择器的products.csv文件:
csv
url,selector,name
https://site-a.com/product1,.price-tag,产品A
https://site-b.com/item2,#price,产品B
运行监控脚本:
bash
python scripts/monitor_prices.py products.csv
3. 库存预警
应用场景: 缺货商品补货时接收通知
bash
agent-browser open
agent-browser snapshot -i
agent-browser get text @e1 # 检查有货或缺货状态
4. 价格历史追踪
应用场景: 建立历史价格数据用于分析
脚本自动记录:
输出:price-history.csv或JSON格式
脚本
monitor_prices.py
主监控脚本功能:
- - 从CSV读取产品列表
- 依次访问每个URL
- 使用CSS选择器提取价格
- 记录带时间戳的结果
- 检测价格变动
- 可选:重大变动时发送警报
使用方法:
bash
python scripts/monitor_prices.py products.csv [--alert-threshold 10]
参数说明:
- - products.csv - 包含URL和选择器的产品列表
- --alert-threshold - 触发警报的变动百分比(默认:10%)
配置
产品列表格式(CSV)
csv
url,selector,name,minprice,maxprice
https://amazon.com/dp/B08N5WRWNW,.a-price-whole,索尼耳机,50,150
https://bestbuy.com/site/12345,.priceView-hero-price,电视,200,500
警报选项
- - 邮件警报 - 配置SMTP设置
- Discord Webhook - 推送至Discord频道
- 文件记录 - 追加至CSV/JSON
- 控制台输出 - 在终端打印变动信息
最佳实践
- 1. 请求频率限制 - 请求间添加延迟(建议30秒以上)
- 错误处理 - 优雅处理页面加载失败
- 选择器稳定性 - 使用稳定CSS选择器,避免动态类名
- 无头模式 - 自动化时使用浏览器无头模式
- 合理调度 - 在营业时间检查价格以确保准确性
示例:每日定时价格检查
bash
每天上午9点运行
0 9 * cd /path/to/skill && python scripts/monitor_prices.py products.csv
故障排除
- - 元素未找到:重新运行快照获取更新引用
- 价格格式问题:调整选择器或使用正则解析
- 页面加载超时:增加超时时间或添加等待条件
- 被网站屏蔽:添加延迟、轮换用户代理或使用住宅代理