Install in seconds
Install this skill
Copy the command and run it in your terminal. You can review the source before installing.
terminal
git clone https://github.com/voltwake/xianyu-monitor

Works with Git. The repository opens in your current directory.

🐟
AutomationJavaScript

Xianyu Monitor

by voltwake

Monitors Xianyu (Goofish) for new second-hand items based on keywords and filters, sending notifications when matches are found.

36 stars4 forksAdded 2026/07/16

Documentation

README

🐟 xianyu-monitor — 闲鱼商品监控 OpenClaw Skill

让你的 AI agent 自动监控闲鱼(Goofish),新上架商品实时推送到 Discord / Telegram。

零成本。不需要 API Key。不需要闲鱼账号。

✨ 功能

  • 🔍 关键词搜索:设定关键词,自动搜索闲鱼
  • 💰 价格过滤:设定最低/最高价格范围
  • 🚫 排除关键词:过滤掉"中介"、"碎屏"等不想要的结果
  • 必含关键词:只看包含"国行"、"256G"等特定词的商品
  • 📍 地区过滤:限定搜索地区
  • 🔄 自动去重:SQLite 数据库记录已发现商品,不会重复推送
  • 📱 实时推送:新商品自动推送到 Discord / Telegram
  • 🎯 多任务并行:同时监控多个关键词,互不干扰

📋 前置条件

  • macOS(需要 AppleScript 控制 Chrome 地址栏)
  • OpenClaw 已安装并运行
  • Google Chrome(脚本会启动一个独立实例,不影响你日常使用的浏览器)
  • Node.js 依赖:puppeteer-corebetter-sqlite3
npm install puppeteer-core better-sqlite3

🔐 登录 vs 未登录

状态 搜索结果范围 排序
未登录 只能看到 6小时以上 发布的商品 有限
已登录 可以看到 实时发布 的商品 完整(新发布→最新)

⚠️ 强烈建议登录闲鱼账号(用小号),否则监控不到最新商品。

🚀 快速开始

1. 启动 Chrome 实例

bash scripts/setup-chrome.sh start

⚠️ Chrome 以非 headless 模式启动(闲鱼检测 headless 浏览器)

2.(推荐)登录闲鱼

在弹出的 Chrome 窗口中访问 goofish.com,用手机扫码或短信登录。Cookie 保存在 ~/.chrome-debug-xianyu,约 7 天有效。

3. 添加监控任务

# 监控 iPhone 16,价格 3000-5000
node scripts/xianyu.js add --keyword "iPhone 16" --min-price 3000 --max-price 5000

# 监控租房,排除中介
node scripts/xianyu.js add --keyword "南山租房" --max-price 3000 --filter "中介费,中介勿扰"

# 监控稀缺品,不限价格
node scripts/xianyu.js add --keyword "Steam Deck 512G"

4. 手动测试

node scripts/xianyu.js scan --hours 24

5. 配置 OpenClaw Cron 定时任务

在 OpenClaw 对话中告诉 agent:

"帮我建一个 cron 任务,每小时跑一次闲鱼监控,有新商品推送到 Discord #xxx 频道"

或手动配置 cron,payload 示例:

运行:bash scripts/setup-chrome.sh start
运行:node scripts/xianyu.js scan --hours 24

解析输出中 --- NEW_ITEMS_JSON --- 和 --- END_NEW_ITEMS_JSON --- 之间的 JSON 数组。
如果有新商品,逐条推送到 Discord。
格式:
🛒 **标题**
💰 ¥价格 | 📍 地区
⏰ 发布时间
🔗 https://www.goofish.com/item?id=商品ID

📖 完整命令

# 添加监控任务
node scripts/xianyu.js add --keyword "搜索词" \
  [--min-price 500] [--max-price 3000] \
  [--filter "排除词1,排除词2"] \
  [--only "必含词1,必含词2"] \
  [--region "深圳,龙华"]

# 查看所有任务
node scripts/xianyu.js list

# 执行扫描
node scripts/xianyu.js scan [--id <task_id>] [--hours 24]

# 查看发现历史
node scripts/xianyu.js history [--id <task_id>] [--limit 20]

# 停用任务
node scripts/xianyu.js remove --id <task_id>

# Chrome 管理
bash scripts/setup-chrome.sh start    # 启动
bash scripts/setup-chrome.sh status   # 检查状态
bash scripts/setup-chrome.sh stop     # 停止

🏗️ 技术原理

闲鱼(goofish.com)有严格的反自动化检测,本工具通过以下方式绕过:

  1. 非 headless Chrome:headless 模式会被闲鱼直接拦截("非法访问")
  2. AppleScript 地址栏导航:首次访问闲鱼时,用 AppleScript 模拟在 Chrome 地址栏输入 URL(page.goto() 会被 baxia 风控拦截)
  3. CDP Input 事件搜索:用 page.click() + page.keyboard.type() 在搜索框中输入关键词(产生 isTrusted=true 事件,与真人点击无差别)
  4. 两步排序:点击"新发布"展开下拉菜单 → 点击"最新"获取实时结果
  5. DOM 被动读取:从渲染后的页面 DOM 中提取商品卡片数据(a[class*="feeds-item-wrap"]
  6. SQLite 去重:与本地数据库比对,筛出新商品
操作 结果
page.goto(searchURL) ❌ 被 baxia 拦截
page.click(搜索框) + type + Enter ✅ 正常
headless Chrome ❌ "非法访问"
非 headless Chrome ✅ 正常

💰 成本

零。 不使用任何付费 API,不需要闲鱼账号。

唯一消耗:Chrome 实例约 200MB 内存 + OpenClaw cron 的模型费用(用 Kimi/Gemini 等便宜模型几乎免费)。

⚠️ 注意事项

  • 扫描间隔建议 ≥ 30 分钟,过于频繁可能触发闲鱼反爬
  • 冷启动(首次运行)可能需要两次 scan 才能成功(第一次建立 session)
  • 当前仅支持 macOS(依赖 AppleScript 控制 Chrome)
  • 建议登录闲鱼账号(小号),未登录只能看到 6 小时前的商品
  • Cookie 约 7 天过期,需重新扫码登录

📄 License

MIT

🔗 相关