
一个智能体按计划从好几个服务收集价格、挂牌和招聘信息,把一团乱理成一张表,只有真出现变化时才提醒你。
你把一个来源描述一次:它的 URL、页面怎么分页、你需要哪些字段。智能体抓取页面,让模型把字段抽进一个固定 schema,按一个稳定的键去重,存一份快照,并写下对着上一次运行的差异。
- 表:sources、runs、items、item_changes
- 带 fetch 加 HTML 转文本清理的 edge function
- 用一个严格字段 schema 的结构化抽取
- 每隔几小时的定时触发
- 邮件或 webhook 告警,加 CSV 导出
把监控做成按来源订阅:二手商付钱看竞品价格,招聘方看职位流,代理公司看线索名单。间隔越短、要 API 访问的,收得越贵。
一个周末
- 先看规则:读 robots.txt 和服务条款,只抓公开页面,网站有官方 API 时优先用它。
- 建 sources 表,带 url、分页模式、css 提示、字段列表、间隔和活跃标记。一行等于一个被监控的服务。
- 写一个 edge function fetch_source:它用一个正常的 user agent 加载 HTML,剥掉脚本和样式,把文本裁到装着挂牌的那部分。
- 把那段文本连同一个严格的 JSON schema(title、price、currency、url、published_at、raw_key)和温度零传给模型。绝不让模型编字段,缺失值必须是 null。
- 按 raw_key 去重:upsert 进 items,当一个被追踪的字段跟存下来的行不同时,往 item_changes 插一条带旧值和新值的记录。
- 加上带退避的重试、每个来源的速率限制,以及一个记录状态、条目数和错误文本的 runs 表,好让一个坏掉的选择器立刻可见。
- 按每个来源的间隔给这个函数排程,然后发一封摘要邮件或 webhook,只列出上次摘要以来 item_changes 里的行。
- 做界面:带健康徽章的来源列表、运行历史、一张可筛选的条目表、一个变更流和一个 CSV 导出按钮。
Build a scraping and monitoring agent. Data: table "sources" (name, url, pagination_pattern, selector_hint, fields jsonb, interval_minutes, active). Table "runs" (source_id, status, items_found, error, started_at, finished_at). Table "items" (source_id, raw_key unique per source, title, price numeric, currency, url, published_at, payload jsonb, first_seen_at, last_seen_at). Table "item_changes" (item_id, field, old_value, new_value, created_at). Server: an edge function that takes a source id, fetches the page with a normal user agent, strips scripts, styles and navigation, trims the text to the listing area, then asks the model to extract rows into a strict JSON schema with temperature zero and null for missing values. Upsert rows into items on raw_key and insert item_changes whenever a tracked field differs. Log every attempt into runs, retry twice with backoff on network errors and respect a per source rate limit. Follow pagination up to a configurable page limit. Automation: a scheduled job that picks active sources whose interval has elapsed, runs them one by one, then sends a digest email or webhook containing only item_changes created since the previous digest. UI: sources page with add and edit form, health badge from the last run, run history with error text, items table with search and filters, a change feed and a CSV export button. Rules: only public pages, honour robots.txt, keep all keys and model calls on the server, enable row level security so each user sees only their own sources and items.















