跳转到主要内容
页面监控用于监控你已经知道的 URL。每次检查都会抓取目标中的每个 URL,将其与上一次保留的快照进行差异比对,并报告该页面是 samechangednewremoved 还是 error。对于定价页面、更新日志、文档页面、招聘信息、状态页面,或任何细微变化也很重要的已知 URL,它都是合适的选择。 本页介绍 scrape 目标。调度、目标与判定、变更追踪、通知和定价在所有监控类型中都是共通的。请参见 监控概览

创建页面监控

创建一个使用 scrape 目标的监控器,并列出一个或多个明确的 URL:
from firecrawl import Firecrawl

firecrawl = Firecrawl(
  # 监控端点需要 API 密钥:
  api_key="fc-YOUR-API-KEY",
)

monitor = firecrawl.create_monitor(
    name="Hacker News AI monitor",
    schedule={"text": "every 30 minutes", "timezone": "UTC"},
    goal=(
        "Alert when a new Hacker News story related to AI enters the top 10. "
        "Ignore changes to stories that are not about AI. "
        "Do not alert on changes outside the top 10."
    ),
    targets=[
        {
            "type": "scrape",
            "urls": ["https://news.ycombinator.com"],
        }
    ],
    notification={
        "email": {
            "enabled": True,
            "recipients": ["alerts@example.com"],
            "includeDiffs": True,
        }
    },
)

print(monitor.id)
你也可以通过 Firecrawl CLI 创建监控器:
CLI
firecrawl monitor create --name "Hacker News AI" \
  --schedule "every 30 minutes" \
  --goal "Alert when a new Hacker News story related to AI enters the top 10. Ignore changes to stories that are not about AI. Do not alert on changes outside the top 10." \
  --page https://news.ycombinator.com

抓取目标

scrape 目标需要 type,以及一个至少包含一个 URL 的 urls 数组。抓取选项会传递到底层的抓取任务。由监控触发的抓取会默认将 maxAge 设为 0,因此除非你显式设置了其他 maxAge,否则每次检查都会执行一次新的抓取。
Scrape target
{
  "type": "scrape",
  "urls": ["https://example.com/pricing"],
  "scrapeOptions": {
    "formats": ["markdown"],
    "maxAge": 0
  }
}

检测字段级变更

默认情况下,页面监控会比较页面 markdown 的差异。若只想在特定字段发生变化时触发告警,例如价格、标题、是否有库存的标记,或列表中的条目,请在目标的 scrapeOptions 中添加 changeTracking 格式。请参见 变更追踪 了解 JSON 模式和混合模式。

通用配置

  • 调度: cron 表达式或自然语言频率,最短间隔为 5 分钟。
  • 目标与判定: 仅在出现有意义的变更时发送告警。
  • 通知: 通过 webhook 和电子邮件发送。
  • 检查结果: 查看每次检查及各页面的差异。
  • 定价: 每次检查每个 URL 消耗 1 个额度,另加可选判定。