5.4 KiB
Firecrawl CLI 完整使用手册(合并版)
我已把之前两段 Firecrawl CLI 内容合并成一份完整可直接导出 Word的文档,你复制粘贴到 Word 里保存即可。
Firecrawl CLI 完整使用手册(合并版)
一、产品介绍
Firecrawl CLI 是 Firecrawl 官方推出的命令行网页数据采集工具,专为终端与 AI 工作流设计,可一键完成单页抓取、全站爬取、站点地图、网页搜索与 AI 结构化提取,输出直接适配 LLM 与代码场景。
核心定位与优势
-
定位:终端级网页数据采集 CLI,将网页转为 LLM 可用的干净 Markdown/结构化数据。
-
优势:
-
开箱即用,无需处理反爬、JS 渲染、代理与格式清洗。
-
支持异步长任务、多格式输出、AI 提取与批量处理。
-
深度集成 Claude Code、Cursor、Windsurf 等 AI 编程工具。
-
二、安装与配置
1. 安装(Node.js 环境)
# 全局安装
npm install -g firecrawl-cli
# 或直接用 npx 免安装运行
npx firecrawl --help
2. 配置 API Key
# 交互式配置 API Key
firecrawl config
# 或设置环境变量
export FIRECRAWL_API_KEY="fc-xxx"
三、核心命令与用法
1. Scrape(单页抓取)
抓取单个 URL,默认输出 Markdown,支持 HTML、JSON、截图等格式。
# 基础抓取(默认 Markdown)
firecrawl https://example.com
# 指定多格式输出
firecrawl https://example.com --format markdown,html,links
# 输出到文件
firecrawl https://example.com -o page.md
2. Crawl(全站爬取)
异步爬取全站链接,返回 Job ID 用于查询进度与结果。
# 启动爬取(返回 Job ID)
firecrawl crawl https://example.com --limit 100 --depth 3
# 等待完成并显示进度
firecrawl crawl https://example.com --wait --progress
# 查询爬取状态
firecrawl crawl <job-id>
3. Map(站点地图)
生成全站 URL 清单,支持子域名、排除路径、去重等。
# 生成站点地图
firecrawl map https://example.com
# 包含子域名、忽略查询参数
firecrawl map https://example.com --include-subdomains --ignore-query-parameters
4. Search(网页搜索+抓取)
联网搜索并抓取结果,支持时间/来源/分类过滤。
# 搜索并抓取结果
firecrawl search "AI trends 2026" --limit 10 --scrape
# 按时间/来源过滤
firecrawl search "tech news" --tbs qdr:d --sources news --pretty
5. Extract(AI 结构化提取)
用 Zod/JSON Schema 从网页抽取结构化数据。
# 用 schema.js 提取商品信息
firecrawl extract schema.js https://example.com/products
四、常用参数
-
--format:输出格式(markdown, html, json, links, screenshot)。 -
--limit:最大爬取/搜索结果数。 -
--depth:爬取深度。 -
--wait:等待任务完成。 -
--progress:显示进度条。 -
-o:输出到文件。 -
--pretty:美化 JSON 输出。
五、与 AI 工具集成
在 Claude Code / Cursor 中一键启用:
npx -y firecrawl-cli@latest init --all --browser
即可让 AI 助手直接调用 Firecrawl 抓取、爬取、搜索网页。
六、常用命令速查表
基础配置(必做)
| 命令 | 用途 | 说明 |
|---|---|---|
firecrawl config |
交互式配置 API Key | 首次使用必执行 |
export FIRECRAWL_API_KEY="fc-xxx" |
临时设置 API Key | 终端会话有效 |
firecrawl --help |
查看所有命令/参数 | 快速查阅用法 |
单页抓取(Scrape)
| 场景 | 命令 |
|---|---|
| 基础抓取(Markdown) | firecrawl https://example.com |
| 输出到文件 | firecrawl https://example.com -o output.md |
| 多格式抓取 | firecrawl https://example.com --format markdown,html,links |
| 抓取并截图 | firecrawl https://example.com --format screenshot -o page.png |
全站爬取(Crawl)
| 场景 | 命令 |
|---|---|
| 启动异步爬取 | firecrawl crawl https://example.com --limit 50 --depth 2 |
| 等待爬取完成 | firecrawl crawl https://example.com --wait --progress --limit 100 |
| 查询爬取状态 | firecrawl crawl <你的Job ID> |
| 爬取结果导出 | firecrawl crawl <Job ID> -o crawl_results.json |
站点地图(Map)
| 场景 | 命令 |
|---|---|
| 生成基础站点地图 | firecrawl map https://example.com |
| 包含子域名 | firecrawl map https://example.com --include-subdomains |
| 忽略查询参数 | firecrawl map https://example.com --ignore-query-parameters |
| 导出站点地图 | firecrawl map https://example.com -o sitemap.txt |
网页搜索+抓取(Search)
| 场景 | 命令 |
|---|---|
| 搜索并抓取结果 | firecrawl search "2026 AI 发展趋势" --limit 10 --scrape |
| 按时间过滤 | firecrawl search "tech news" --tbs qdr:d --scrape |
| 美化 JSON 输出 | firecrawl search "Python 教程" --pretty --scrape |
AI 结构化提取(Extract)
| 场景 | 命令 |
|---|---|
| 用 Schema 提取数据 | firecrawl extract schema.js https://example.com/products |
| 示例 Schema 文件(schema.js): |
import { z } from "zod";
export default z.object({
productName: z.string(),
price: z.string(),
rating: z.number().optional(),
url: z.string()
});
导出步骤
-
全选上面所有文字 → 复制
-
打开 Microsoft Word → 新建空白文档 → 粘贴
-
保存为
.docx即可
需要我再帮你精简成一页版或做成带目录的正式文档吗?
(注:文档部分内容可能由 AI 生成)