想象一下,你想让 AI 学习某个网站的内容(比如公司文档、产品介绍、技术教程),但网页上有很多广告、导航栏、侧边栏等无关内容。传统的网页爬虫会把这些乱七八糟的东西都抓下来,AI 看了会"消化不良"。
Firecrawl 就像是一个"智能清洁工":
使用场景:
简单来说:专为 AI 应用设计的网页爬虫,能将任意网站快速转化为干净、结构化的数据,让 AI 能更好地理解和学习。
完整的使用教程请参考:https://docs.firecrawl.dev/zh/introduction
为什么要本地部署?
前提条件: 确保你已经安装了 Docker(查看安装教程[1])
# 克隆 Firecrawl 仓库
git clone https://github.com/mendableai/firecrawl.git
# 进入项目目录
cd firecrawl/apps/api如果默认端口被占用,可以修改成其他端口。
文件位置: docker-compose.yml

作用: 本地使用时不需要 API Key,更方便。
配置方法:
在 .env 文件中添加:
# 关闭授权验证
USE_DB_AUTHENTICATION=false作用: 加速 Go 依赖包的下载,避免构建时卡住。
配置方法:
在 Dockerfile 中找到安装 Go 依赖的部分,添加代理配置:
# Install Go dependencies and build parser lib
RUN cd /app/sharedLibs/go-html-to-md && \
go env -w GOPROXY=https://goproxy.cn && \
go mod tidy && \
go build -o libhtml-to-markdown.so -buildmode=c-shared html-to-markdown.go && \
chmod +x libhtml-to-markdown.so# 确保在 firecrawl/apps/api 目录下
cd firecrawl/apps/api
# 启动 Firecrawl
docker compose -p firecrawl up -d说明:
-p firecrawl:项目名称-d:后台运行访问地址: 启动成功后,服务运行在 http://localhost:3002(默认端口)
docker compose -p firecrawl down现象: 运行 docker compose up 时报错:
SSL error: unknown error; class=Ssl (16)
error: failed to get `nodesig` as a dependency
failed to load source for dependency `nodesig`原因:
解决方法:使用镜像源和优化网络配置
需要替换 apps/api/Dockerfile 文件的内容,使用国内镜像加速。
完整的 Dockerfile 配置(已优化,直接复制替换):
# syntax=docker/dockerfile:1
FROM node:22-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV CI=true
RUN corepack enable
# ===== 构建 Go 共享库 =====
FROM golang:1.24 AS go-build
WORKDIR /app
COPY sharedLibs/go-html-to-md ./sharedLibs/go-html-to-md
# 使用国内 Go 代理加速下载
RUN cd /app/sharedLibs/go-html-to-md && \
go env -w GOPROXY=https://goproxy.cn && \
go mod tidy && \
go build -o libhtml-to-markdown.so -buildmode=c-shared html-to-markdown.go && \
chmod +x libhtml-to-markdown.so
# ===== 构建应用 =====
FROM base AS build
WORKDIR /app
# 安装系统依赖(添加 ca-certificates 和 git 解决 SSL 问题)
RUN apt-get update && apt-get install -y \
curl \
build-essential \
pkg-config \
python3 \
ca-certificates \
git \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# 安装 Rust
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME
# 配置 Cargo 使用清华大学镜像源(加速下载)
RUN mkdir -p $CARGO_HOME && \
echo '[source.crates-io]' > $CARGO_HOME/config.toml && \
echo 'replace-with = "tuna"' >> $CARGO_HOME/config.toml && \
echo '' >> $CARGO_HOME/config.toml && \
echo '[source.tuna]' >> $CARGO_HOME/config.toml && \
echo 'registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"' >> $CARGO_HOME/config.toml && \
echo '' >> $CARGO_HOME/config.toml && \
echo '[net]' >> $CARGO_HOME/config.toml && \
echo 'git-fetch-with-cli = true' >> $CARGO_HOME/config.toml && \
echo 'retry = 10' >> $CARGO_HOME/config.toml
# 配置 Git 优化网络连接
RUN git config --global http.postBuffer 524288000 && \
git config --global http.lowSpeedLimit 0 && \
git config --global http.lowSpeedTime 999999 && \
git config --global http.sslVerify true && \
git config --global core.compression 0
# 设置 Cargo 和 Rust 环境变量
ENV CARGO_NET_RETRY=10 \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rust-static \
RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rust-static/rustup
# 复制源文件
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
COPY . .
# 预先克隆 nodesig 仓库,使用多个备选镜像源(解决下载失败问题)
RUN mkdir -p /usr/local/cargo/git/db && \
cd /usr/local/cargo/git/db && \
(git clone --bare --depth 1 https://github.com/firecrawl/nodesig nodesig-e0a68ad4afa2e088 || \
git clone --bare --depth 1 https://hub.nuaa.cf/firecrawl/nodesig nodesig-e0a68ad4afa2e088 || \
git clone --bare --depth 1 https://gh.api.99988866.xyz/https://github.com/firecrawl/nodesig nodesig-e0a68ad4afa2e088 || \
git clone --bare --depth 1 https://cors.isteed.cc/github.com/firecrawl/nodesig nodesig-e0a68ad4afa2e088 || \
git clone --bare --depth 1 https://github.moeyy.xyz/https://github.com/firecrawl/nodesig nodesig-e0a68ad4afa2e088 || \
(git config --global http.sslVerify false && \
git clone --bare --depth 1 https://github.com/firecrawl/nodesig nodesig-e0a68ad4afa2e088 && \
git config --global http.sslVerify true) || \
echo "Warning: All mirrors failed, will try during build") && \
chmod -R 777 /usr/local/cargo/git/db || true
# 安装依赖
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/native/target \
pnpm install --frozen-lockfile
# 构建应用
RUN pnpm run build
# 删除开发依赖
RUN pnpm prune --prod --ignore-scripts
# ===== 运行时环境 =====
FROM base AS runtime
# 安装运行时依赖
RUN apt-get update && apt-get install -y \
git \
procps \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 8080
WORKDIR /app
# 复制构建产物
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/native ./native
# 复制 Go 共享库
COPY --from=go-build /app/sharedLibs/go-html-to-md/libhtml-to-markdown.so ./sharedLibs/go-html-to-md/
CMD ["node", "dist/src/harness.js", "--start-docker"]配置说明:
goproxy.cn 加速 Go 包下载使用方法:
apps/api/Dockerfile 文件docker compose -p firecrawl up -d什么是 MCP?
MCP (Model Context Protocol) 是一个协议,让 AI 工具(如 Claude Desktop、Windsurf 等)可以直接调用 Firecrawl 的功能。
使用场景:
配置教程: https://docs.firecrawl.dev/zh/mcp-server
简单说明:
通过 MCP,你可以让 AI 助手在对话时自动爬取网页,不需要手动复制粘贴网页内容。比如你问 Claude:"帮我总结一下这个网页的内容 https://example.com",它就会自动调用 Firecrawl 爬取并分析。
抓取单个网页:
curl -X POST http://localhost:3002/v1/scrape \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com"
}'抓取整个网站:
curl -X POST http://localhost:3002/v1/crawl \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com",
"limit": 100
}'提取结构化数据:
curl -X POST http://localhost:3002/v1/scrape \
-H 'Content-Type: application/json' \
-d '{
"url": "https://example.com",
"formats": ["markdown", "html"]
}'通过这篇教程,你应该已经掌握了:
下一步建议:
小提示:
祝你使用愉快!🎉
[1] 查看安装教程: https://github.com/mendableai/firecrawl/blob/main/CONTRIBUTING.md#alternative-using-docker-compose
[2] 官方文档: https://docs.firecrawl.dev/zh/introduction