Facebook Group Monitor Skill
Overview
Playwright-based headless browser scraper for Facebook groups. Default behavior:
captures a stitched "feed strip" (scrolls 3× viewport, crops to feed column,
stitches into 1 JPEG) → agent calls vision model once with a custom prompt to
extract and interpret all new posts in a single LLM call.
Requires one-time manual login via terminal to establish a persistent browser session.
Setup
See references/SETUP.md for installation and first-time login instructions.
File Locations (after install)
- - Script: INLINECODE0
- Shell wrapper: INLINECODE1
- Browser session: auto-created at
scripts/.browser-data/ (persistent login) - Seen posts: auto-created at
scripts/.seen-posts.json (dedup tracking) - Screenshots:
scripts/screenshots/ or custom INLINECODE5
Commands
1. Check login session
scripts/fb-group-monitor.sh status
Output:
CODEBLOCK1
2. Scrape new posts (with feed strip screenshot)
CODEBLOCK2
Parameters:
- -
GROUP_URL: Full URL (https://www.facebook.com/groups/123456) or just group ID - INLINECODE7 : Max posts to scrape (default: 10)
- INLINECODE8 : ⚠️ REQUIRED for vision — save screenshots in agent workspace so image tool can read them
- INLINECODE9 : Skip screenshots (faster, text-only mode)
Example:
CODEBLOCK3
Output JSON (with feed strip screenshot):
CODEBLOCK4
Note: feed_screenshot is a single stitched JPEG covering the full feed (3 viewport scrolls).
Individual posts no longer have a screenshot_path — use feed_screenshot (top-level) instead.
3. Clean old screenshots
scripts/fb-group-monitor.sh clean-shots
Auto-removes screenshots older than 48h and caps at 100 max. Script also auto-cleans before each scrape.
4. Login (one-time, from terminal)
scripts/fb-group-monitor.sh login
Opens browser, login manually, press Enter to save session. Session lasts weeks/months.
Agent Workflow
When triggered by cron or user request to check a group:
Step 1: Scrape
scripts/fb-group-monitor.sh scrape "<GROUP_URL>" --limit 10 --shots-dir ./temp-screenshots
⚠️ Use --shots-dir pointing to a path within the workspace so the image tool can access screenshots.
Step 2: Analyze feed screenshot + combine with text
If feed_screenshot is present (1 stitched image covering the full feed):
- - Compose a dynamic prompt using the author list from the JSON, so vision focuses on the correct new posts (the feed strip also contains already-seen posts)
- Call image tool with both
image and prompt parameters:
image tool:
image: <feed_screenshot path>
prompt: "Facebook group feed. Find and analyze posts by these people (new posts to process):
- [Author 1]: "[first few words of text from JSON]" — N images
- [Author 2]: "[first few words of text from JSON]"
...
For EACH post, do 2 things:
1. EXTRACT: book/product name, author/publisher (read from cover), price (including handwritten prices), condition (new/used/marked/yellowed).
2. INTERPRET: is the deal worth it (price vs market if known), is the item rare/valuable, actual condition assessment from photos."
- - ⚠️ NEVER call image tool with empty
{} — default prompt just describes the image generically - ⚠️ Feed strip includes old posts — always include author + text snippet so vision targets the right posts
- After getting vision result: match by author, add
url from JSON - Prioritize image content over truncated
text field ("see more" posts)
If feed_screenshot is absent (screenshot failed):
- - Read directly from
text field of each post - Summarize available information, note "no screenshot available"
Step 3: Report to user
MUST include the original post link in each item for verification.
CODEBLOCK9
Step 4: If no new posts → stay silent (no notification)
Step 5: If success == false → report error briefly
⚠️ Anti-duplicate rule
- - Send Telegram only ONCE per run, regardless of whether vision succeeded or failed
- If
message tool returns an error → report once and stop, do NOT retry - If vision fails → fallback to text, send once with note "⚠️ Vision unavailable, text only"
Important Notes
- - Rate limiting: Recommended cron interval ≥ 2 hours — safe for Facebook
- Session expired: If error "Not logged in" → run
login from terminal - UI changes: Facebook updates DOM frequently → selectors may need updates
- "See more": Text is truncated — feed strip screenshot usually has complete content
- Feed strip: Scrolls 3× viewport height, crops to feed column, stitches 1 JPEG — reduces vision calls from N to 1
- Screenshot quality: JPEG 82% — sufficient for LLM vision to read text and identify product images
- Vision model: Use a vision-capable model (e.g. Gemini Flash) for the image tool call
Facebook 群组监控技能
概述
基于Playwright的无头浏览器爬虫,用于监控Facebook群组。默认行为:
捕获拼接的动态条(滚动3倍视口高度,裁剪为动态列,拼接成1张JPEG图片)→ 代理使用自定义提示词调用一次视觉模型,在单次LLM调用中提取并解释所有新帖子。
需通过终端进行一次手动登录以建立持久浏览器会话。
设置
安装和首次登录说明请参阅 references/SETUP.md。
文件位置(安装后)
- - 脚本:scripts/fb-group-monitor.py
- Shell封装:scripts/fb-group-monitor.sh
- 浏览器会话:自动创建于 scripts/.browser-data/(持久登录)
- 已见帖子:自动创建于 scripts/.seen-posts.json(去重跟踪)
- 截图:scripts/screenshots/ 或自定义 --shots-dir
命令
1. 检查登录会话
bash
scripts/fb-group-monitor.sh status
输出:
json
{success: true, action: status, message: Session active — logged in to Facebook.}
2. 抓取新帖子(含动态条截图)
bash
scripts/fb-group-monitor.sh scrape
[--limit N] [--shots-dir ]
参数:
- - GROUP_URL:完整URL(https://www.facebook.com/groups/123456)或仅群组ID
- --limit N:最大抓取帖子数(默认:10)
- --shots-dir :⚠️ 视觉分析必需 — 在代理工作区保存截图,以便图片工具可读取
- --no-shots:跳过截图(更快,纯文本模式)
示例:
bash
scripts/fb-group-monitor.sh scrape https://www.facebook.com/groups/123456789 --limit 10 --shots-dir ./temp-screenshots
输出JSON(含动态条截图):
json
{
success: true,
action: scrape,
group_name: 示例群组名称,
group_url: https://www.facebook.com/groups/123456789,
total_scraped: 6,
new_count: 3,
feedscreenshot: /path/to/temp-screenshots/feedabc12345_1741800000.jpg,
posts: [
{
author: 发帖人姓名,
text: 帖子内容(可能被Facebook的查看更多截断)...,
url: https://facebook.com/groups/123456/posts/789,
images: 3
},
{
author: 另一位发帖人,
text: 纯文本帖子,无图片...,
url: https://facebook.com/groups/123456/posts/790,
images: 0
}
],
message: 找到3个新帖子 / 共6个。
}
注意:feed_screenshot 是一张覆盖完整动态的拼接JPEG(3倍视口滚动)。
单个帖子不再有 screenshotpath — 请改用顶层 feedscreenshot。
3. 清理旧截图
bash
scripts/fb-group-monitor.sh clean-shots
自动删除超过48小时的截图,并限制最多100张。脚本在每次抓取前也会自动清理。
4. 登录(一次性,从终端执行)
bash
scripts/fb-group-monitor.sh login
打开浏览器,手动登录,按回车保存会话。会话可持续数周/数月。
代理工作流程
当通过cron或用户请求触发检查群组时:
步骤1:抓取
bash
scripts/fb-group-monitor.sh scrape --limit 10 --shots-dir ./temp-screenshots
⚠️ 使用 --shots-dir 指向工作区内的路径,以便图片工具可访问截图。
步骤2:分析动态截图 + 结合文本
如果存在 feed_screenshot(1张覆盖完整动态的拼接图片):
- - 使用JSON中的作者列表构建动态提示词,使视觉模型聚焦于正确的新帖子(动态条也包含已见帖子)
- 使用 image 和 prompt 两个参数调用图片工具:
图片工具:
image:
prompt: Facebook群组动态。查找并分析以下人员的帖子(需处理的新帖子):
- [作者1]:[JSON中文本的前几个字] — N张图片
- [作者2]:[JSON中文本的前几个字]
...
对每个帖子,执行2项操作:
1. 提取:书籍/产品名称、作者/出版商(从封面读取)、价格(含手写价格)、品相(全新/二手/污损/泛黄)。
2. 解读:是否值得购买(价格与市场价对比,如已知)、物品是否稀有/有价值、根据照片的实际品相评估。
- - ⚠️ 切勿使用空 {} 调用图片工具 — 默认提示词只会泛泛描述图片
- ⚠️ 动态条包含旧帖子 — 务必包含作者+文本片段,使视觉模型定位到正确帖子
- 获取视觉结果后:按作者匹配,从JSON添加 url
- 优先使用图片内容而非截断的 text 字段(查看更多帖子)
如果缺少 feed_screenshot(截图失败):
- - 直接从每个帖子的 text 字段读取
- 汇总可用信息,注明无可用截图
步骤3:向用户报告
必须在每个项目中包含原始帖子链接以供验证。
每个新帖子的格式:
📌 [标题/摘要]
👤 作者:[作者]
💰 价格:[价格或未知]
📝 品相:[描述]
💡 备注:[交易评估或见解,如有]
🔗 [帖子URL]
步骤4:如无新帖子 → 保持静默(不发送通知)
步骤5:如 success == false → 简要报告错误
⚠️ 防重复规则
- - 每次运行仅发送一次Telegram,无论视觉分析成功或失败
- 如 message 工具返回错误 → 报告一次后停止,不重试
- 如视觉分析失败 → 回退到文本,发送一次并注明⚠️ 视觉分析不可用,仅文本
重要说明
- - 速率限制:建议cron间隔 ≥ 2小时 — 对Facebook安全
- 会话过期:如出现未登录错误 → 从终端运行 login
- UI变更:Facebook频繁更新DOM → 选择器可能需要更新
- 查看更多:文本被截断 — 动态条截图通常包含完整内容
- 动态条:滚动3倍视口高度,裁剪为动态列,拼接为1张JPEG — 将视觉调用从N次减少到1次
- 截图质量:JPEG 82% — 足以让LLM视觉模型读取文本和识别产品图片
- 视觉模型:使用支持视觉的模型(如Gemini Flash)进行图片工具调用