安装
npx -y firecrawl-cli@latest init --all --browser
--all会将 Firecrawl 技能安装到所有检测到的 AI 编码代理中--browser会自动打开浏览器以完成 Firecrawl 身份验证
安装这些技能后,请重启你的代理,以便其发现它们。
CLI
# 使用 npm 全局安装
npm install -g firecrawl-cli
身份验证
登录
CLI
# 交互式登录(打开浏览器或提示输入 API 密钥)
firecrawl login
# 使用浏览器身份验证登录(推荐用于代理)
firecrawl login --browser
# 直接使用 API 密钥登录
firecrawl login --api-key fc-YOUR-API-KEY
# 或通过环境变量设置
export FIRECRAWL_API_KEY=fc-YOUR-API-KEY
查看配置
CLI
# 查看当前配置和身份验证状态
firecrawl view-config
退出登录
CLI
# 清除已存储的凭据
firecrawl logout
自托管 / 本地开发
--api-url 参数:
CLI
# 使用本地 Firecrawl 实例(无需 API 密钥)
firecrawl --api-url http://localhost:3002 scrape https://example.com
# Or set via environment variable
export FIRECRAWL_API_URL=http://localhost:3002
firecrawl scrape https://example.com
# Configure and persist the custom API URL
firecrawl config --api-url http://localhost:3002
https://api.firecrawl.dev)时,会自动跳过 API 密钥验证,因此你在本地实例中可以在无需 API 密钥的情况下使用 Firecrawl。
检查状态
CLI
firecrawl --status
🔥 firecrawl cli v1.16.2
● Authenticated via FIRECRAWL_API_KEY
Concurrency: 0/100 jobs (parallel scrape limit)
Credits: 500,000 remaining
- 并发数 (Concurrency) :最大并行任务数。并行操作应尽量接近该上限,但不要超过。
- 额度 (Credits) :剩余 API 额度。每次抓取/爬取都会消耗额度。
命令
Scrape
使用
--only-main-content 即可获取不含导航栏、页脚和广告的干净输出。对于大多数只需要文章或主页面内容的用例,推荐使用该选项。CLI
# 抓取 URL(默认:markdown 输出)
firecrawl https://example.com
# 或使用显式的 scrape 命令
firecrawl scrape https://example.com
# 推荐:使用 --only-main-content 获取不含导航/页脚的干净输出
firecrawl https://example.com --only-main-content
输出 formats 类型
CLI
# 获取 HTML 输出
firecrawl https://example.com --html
# 多种格式(返回 JSON)
firecrawl https://example.com --format markdown,links
# 从页面获取图片
firecrawl https://example.com --format images
# 获取页面内容摘要
firecrawl https://example.com --format summary
# 跟踪页面变化
firecrawl https://example.com --format changeTracking
# 可用格式:markdown, html, rawHtml, links, screenshot, json, images, summary, changeTracking, attributes, branding
抓取选项
CLI
# 仅提取主要内容(移除导航和页脚)
firecrawl https://example.com --only-main-content
# Wait for JavaScript rendering
firecrawl https://example.com --wait-for 3000
# Take a screenshot
firecrawl https://example.com --screenshot
# 使用 schema 提取结构化 JSON
firecrawl https://example.com --format json --schema '{"type":"object","properties":{"title":{"type":"string"}}}'
# 在提取前执行轻量级 scrape actions
firecrawl https://example.com --actions '[{"type":"wait","milliseconds":1000}]'
# 选择代理模式
firecrawl https://example.com --proxy basic
# Include/exclude specific HTML tags
firecrawl https://example.com --include-tags article,main
firecrawl https://example.com --exclude-tags nav,footer
# Save output to file
firecrawl https://example.com -o output.md
# Pretty print JSON output
firecrawl https://example.com --format markdown,links --pretty
# Force JSON output even with single format
firecrawl https://example.com --json
# Show request timing information
firecrawl https://example.com --timing
| 选项 | 简写 | 描述 |
|---|---|---|
--url <url> | -u | 要抓取的 URL (位置参数的替代方式) |
--format <formats> | -f | 输出 formats (逗号分隔) :markdown, html, rawHtml, links, screenshot, json, images, summary, changeTracking, attributes, branding |
--html | -H | --format html 的快捷方式 |
--only-main-content | 仅提取主要内容 | |
--wait-for <ms> | 等待 JS 渲染的时间 (毫秒) | |
--screenshot | 生成页面截图 | |
--full-page-screenshot | 生成整页截图 | |
--include-tags <tags> | 要包含的 HTML 标签 (逗号分隔) | |
--exclude-tags <tags> | 要排除的 HTML 标签 (逗号分隔) | |
--schema <json> | 用于结构化提取的 JSON schema | |
--schema-file <path> | JSON schema 文件路径 | |
--actions <json> | 抓取期间要执行的 JSON actions 数组 | |
--actions-file <path> | JSON actions 文件路径 | |
--proxy <proxy> | 抓取使用的代理模式 (例如 auto 或 basic) | |
--output <path> | -o | 将输出保存到文件 |
--json | 即使只有单一 format 也强制输出 JSON | |
--pretty | 对 JSON 输出进行格式化打印 | |
--timing | 显示请求耗时和其他有用信息 |
搜索
CLI
# 搜索网络
firecrawl search "web scraping tutorials"
# 限制结果数量
firecrawl search "AI news" --limit 10
# 美化打印结果
firecrawl search "machine learning" --pretty
搜索选项
CLI
# Search specific sources
firecrawl search "AI" --sources web,news,images
# Search with category filters
firecrawl search "react hooks" --categories github
firecrawl search "machine learning" --categories research,pdf
# Time-based filtering
firecrawl search "tech news" --tbs qdr:h # Last hour
firecrawl search "tech news" --tbs qdr:d # Last day
firecrawl search "tech news" --tbs qdr:w # Last week
firecrawl search "tech news" --tbs qdr:m # 过去一个月
firecrawl search "tech news" --tbs qdr:y # Last year
# Location-based search
firecrawl search "restaurants" --location "Berlin,Germany" --country DE
# Search and scrape results
firecrawl search "documentation" --scrape --scrape-formats markdown
# Save to file
firecrawl search "firecrawl" --pretty -o results.json
| 选项 | 描述 |
|---|---|
--limit <number> | 结果数量上限 (默认:5,最大:100) |
--sources <sources> | 要搜索的数据源:web、images、news (逗号分隔) |
--categories <categories> | 按类别过滤:github、research、pdf (逗号分隔) |
--tbs <value> | 时间过滤:qdr:h (小时) 、qdr:d (天) 、qdr:w (周) 、qdr:m (月) 、qdr:y (年) |
--location <location> | 地域定向 (例如:“Berlin,Germany”) |
--country <code> | ISO 国家代码 (默认:US) |
--timeout <ms> | 以毫秒为单位的超时时间 (默认:60000) |
--ignore-invalid-urls | 排除对其他 Firecrawl 端点无效的 URL |
--scrape | 抓取搜索结果 |
--scrape-formats <formats> | 抓取内容的 formats (默认:markdown) |
--only-main-content | 抓取时仅包含主要内容 (默认:true) |
--json | 以 JSON 格式输出 |
--output <path> | 将输出保存到文件 |
--pretty | 以易读格式打印 JSON 输出 |
Map
CLI
# 发现网站上的所有 URL
firecrawl map https://example.com
# Output as JSON
firecrawl map https://example.com --json
# Limit number of URLs
firecrawl map https://example.com --limit 500
Map 命令选项
CLI
# Filter URLs by search query
firecrawl map https://example.com --search "blog"
# Include subdomains
firecrawl map https://example.com --include-subdomains
# 控制站点地图使用方式
firecrawl map https://example.com --sitemap include # 使用站点地图
firecrawl map https://example.com --sitemap skip # 跳过站点地图
firecrawl map https://example.com --sitemap only # 仅使用站点地图
# Ignore query parameters (dedupe URLs)
firecrawl map https://example.com --ignore-query-parameters
# Wait for map to complete with timeout
firecrawl map https://example.com --wait --timeout 60
# Save to file
firecrawl map https://example.com -o urls.txt
firecrawl map https://example.com --json --pretty -o urls.json
| 选项 | 描述 |
|---|---|
--url <url> | 要进行 Map 的 URL (可替代位置参数) |
--limit <number> | 要发现的最大 URL 数量 |
--search <query> | 根据搜索查询筛选 URL |
--sitemap <mode> | Sitemap 处理模式:include、skip、only |
--include-subdomains | 包含子域名 |
--ignore-query-parameters | 将带有不同参数的 URL 视为同一 URL |
--wait | 等待 Map 完成 |
--timeout <seconds> | 超时时间 (秒) |
--json | 以 JSON 格式输出 |
--output <path> | 将输出保存到文件 |
--pretty | 以易读格式打印 JSON 输出 |
交互
CLI
# 1. 抓取 Amazon 首页(scrape ID 自动保存)
firecrawl scrape https://www.amazon.com
# 2. 交互 — 搜索商品并获取价格
firecrawl interact "Search for iPhone 16 Pro Max"
firecrawl interact "Click on the first result and tell me the price"
# 3. 停止会话
firecrawl interact stop
| 选项 | 描述 |
|---|---|
-p, --prompt <text> | AI prompt (可替代位置参数) |
-c, --code <code> | 在当前页面会话中执行代码 |
-s, --scrape-id <id> | 抓取任务 ID (默认:最近一次抓取) |
--python | 以 Python/Playwright 执行代码 |
--node | 以 Node.js/Playwright 执行代码 (默认) |
--bash | 以 Bash 执行代码 |
--timeout <seconds> | 超时时间 (秒) (1-300,默认:30) |
--output <path> | 将输出保存到文件 |
--json | 以 JSON 格式输出 |
Crawl
CLI
# Start a crawl (returns job ID immediately)
firecrawl crawl https://example.com
# Wait for crawl to complete
firecrawl crawl https://example.com --wait
# 等待并显示进度指示器
firecrawl crawl https://example.com --wait --progress
查看抓取状态
CLI
# 使用作业 ID 检查爬取状态
firecrawl crawl <job-id>
# 真实作业 ID 示例
firecrawl crawl 550e8400-e29b-41d4-a716-446655440000
Crawl 选项
CLI
# Limit crawl depth and pages
firecrawl crawl https://example.com --limit 100 --max-depth 3 --wait
# Include only specific paths
firecrawl crawl https://example.com --include-paths /blog,/docs --wait
# Exclude specific paths
firecrawl crawl https://example.com --exclude-paths /admin,/login --wait
# Include subdomains
firecrawl crawl https://example.com --allow-subdomains --wait
# Crawl entire domain
firecrawl crawl https://example.com --crawl-entire-domain --wait
# Rate limiting
firecrawl crawl https://example.com --delay 1000 --max-concurrency 2 --wait
# 将爬取选项传递给每个已爬取的页面
firecrawl crawl https://example.com --scrape-options '{"formats":["markdown"],"onlyMainContent":true}'
# 将爬取完成事件发送到 webhook
firecrawl crawl https://example.com --webhook '{"url":"https://example.com/webhook","events":["completed"]}'
# 取消正在进行的爬取任务
firecrawl crawl <job-id> --cancel
# 自定义轮询间隔和超时时间
firecrawl crawl https://example.com --wait --poll-interval 10 --timeout 300
# Save results to file
firecrawl crawl https://example.com --wait --pretty -o results.json
| 选项 | 描述 |
|---|---|
--url <url> | 要爬取的 URL (位置参数的替代方式) |
--wait | 等待爬取完成 |
--progress | 等待期间显示进度指示器 |
--poll-interval <seconds> | 轮询间隔 (默认:5 秒) |
--timeout <seconds> | 等待时的超时时长 |
--status | 检查已有爬取任务的状态 |
--limit <number> | 最大爬取页面数 |
--max-depth <number> | 最大爬取深度 |
--include-paths <paths> | 要包含的路径 (逗号分隔) |
--exclude-paths <paths> | 要排除的路径 (逗号分隔) |
--sitemap <mode> | Sitemap 处理方式:include、skip、only |
--allow-subdomains | 包含子域名 |
--allow-external-links | 跟随外部链接 |
--crawl-entire-domain | 爬取整个域名 |
--ignore-query-parameters | 将具有不同参数的 URL 视为相同 |
--delay <ms> | 请求之间的延迟 |
--max-concurrency <n> | 最大并发请求数 |
--scrape-options <json> | 传递给每个页面的 JSON 抓取选项 |
--scrape-options-file <path> | 抓取选项 JSON 文件路径 |
--webhook <url-or-json> | Webhook URL 或配置 |
--cancel | 通过 job ID 取消活动中的爬取任务 |
--output <path> | 将输出保存到文件 |
--pretty | 以更易读的格式输出 JSON |
Agent
CLI
# 基本用法 - URL 是可选的
firecrawl agent "Find the top 5 AI startups and their funding amounts" --wait
# 聚焦特定 URL
firecrawl agent "Compare pricing plans" --urls https://slack.com/pricing,https://teams.microsoft.com/pricing --wait
# 使用 schema 实现结构化输出
firecrawl agent "Get company information" --urls https://example.com --schema '{"type":"object","properties":{"name":{"type":"string"},"founded":{"type":"number"}}}' --wait
# 从文件加载 schema
firecrawl agent "Get product details" --urls https://example.com --schema-file schema.json --wait
代理 选项
CLI
# 使用 Spark 1 Pro 提高准确性
firecrawl agent "Competitive analysis across multiple domains" --model spark-1-pro --wait
# Set max credits to limit costs
firecrawl agent "Gather contact information from company websites" --max-credits 100 --wait
# Check status of an existing job
firecrawl agent <job-id> --status
# 将代理事件发送到 webhook
firecrawl agent "Extract product details" --urls https://example.com --webhook '{"url":"https://example.com/webhook","events":["completed","failed"]}'
# 取消活跃的代理任务
firecrawl agent <job-id> --cancel
# Custom polling interval and timeout
firecrawl agent "Summarize recent blog posts" --wait --poll-interval 10 --timeout 300
# Save output to file
firecrawl agent "Find pricing information" --urls https://example.com --wait -o pricing.json --pretty
| 选项 | 说明 |
|---|---|
--urls <urls> | 可选的 URL 列表,用于限定代理的处理范围 (用逗号分隔) |
--model <model> | 使用的模型:spark-1-mini (默认,成本低 60%) 或 spark-1-pro (精度更高) |
--schema <json> | 用于结构化输出的 JSON schema (内联 JSON 字符串) |
--schema-file <path> | 用于结构化输出的 JSON schema 文件路径 |
--max-credits <number> | 最多可消耗的额度 (达到上限时任务失败) |
--webhook <url-or-json> | Webhook URL 或配置 |
--status | 检查已有代理任务的状态 |
--cancel | 通过任务 ID 取消正在运行的代理任务 |
--wait | 等待代理任务完成后再返回结果 |
--poll-interval <seconds> | 等待时的轮询间隔 (默认:5) |
--timeout <seconds> | 等待时的超时时间 (默认:无限制) |
--output <path> | 将输出保存到文件 |
--json | 以 JSON 格式输出 |
额度使用情况
CLI
# View credit usage
firecrawl credit-usage
# 以 JSON 格式输出
firecrawl credit-usage --json --pretty
Version
CLI
firecrawl version
# 或
firecrawl --version
全局选项
| 选项 | 简写 | 说明 |
|---|---|---|
--status | 显示版本、认证状态、并发数和额度 | |
--api-key <key> | -k | 在此命令中临时覆盖已保存的 API 密钥 |
--api-url <url> | 使用自定义 API URL (用于自托管/本地开发) | |
--help | -h | 显示命令帮助信息 |
--version | -V | 显示 CLI 版本 |
输出处理
CLI
# 将 Markdown 通过管道传递给另一个命令
firecrawl https://example.com | head -50
# 重定向到文件
firecrawl https://example.com > output.md
# 保存格式化后的 JSON
firecrawl https://example.com --format markdown,links --pretty -o data.json
formats 的行为
- 单一 format:输出原始内容(markdown 文本、HTML 等)
- 多个 formats:输出包含所有请求数据的 JSON
CLI
# 原始 markdown 输出
firecrawl https://example.com --format markdown
# 使用多个 formats 的 JSON 输出
firecrawl https://example.com --format markdown,links
示例
快速抓取
CLI
# 从 URL 获取 Markdown 内容(使用 --only-main-content 获取简洁输出)
firecrawl https://docs.firecrawl.dev --only-main-content
# Get HTML content
firecrawl https://example.com --html -o page.html
整站爬取
CLI
# 爬取文档站点并设置限制
firecrawl crawl https://docs.example.com --limit 50 --max-depth 2 --wait --progress -o docs.json
站点发现
CLI
# 查找所有博客文章
firecrawl map https://example.com --search "blog" -o blog-urls.txt
研究工作流
CLI
# 搜索并抓取结果用于研究
firecrawl search "machine learning best practices 2024" --scrape --scrape-formats markdown --pretty
智能体
CLI
# URL 可选
firecrawl agent "Find the top 5 AI startups and their funding amounts" --wait
# 针对特定 URL
firecrawl agent "Compare pricing plans" --urls https://slack.com/pricing,https://teams.microsoft.com/pricing --wait
与其他工具结合使用
CLI
# Extract URLs from search results
jq -r '.data.web[].url' search-results.json
# Get titles from search results
jq -r '.data.web[] | "\(.title): \(.url)"' search-results.json
# 提取链接并使用 jq 处理
firecrawl https://example.com --format links | jq '.links[].url'
# Count URLs from map
firecrawl map https://example.com | wc -l
遥测
- CLI 版本、操作系统和 Node.js 版本
- 检测到的开发工具(例如 Cursor、VS Code、Claude Code)
CLI
export FIRECRAWL_NO_TELEMETRY=1
开源
你是需要 Firecrawl API 密钥的 AI 代理吗?请参见 firecrawl.dev/agent-onboarding/SKILL.md 获取自动化入门说明。

