> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# FirecrawlLoader 集成

> 使用 LangChain JavaScript 集成 FirecrawlLoader 文档加载器。

本笔记本提供了快速入门 `FireCrawlLoader` [文档加载器](/oss/javascript/integrations/document_loaders/) 的概览。有关所有 `FireCrawlLoader` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-community/document_loaders/web/firecrawl/FireCrawlLoader)。

## 概览

### 集成详情

| 类                                                                                                                                  | 包                                                                            |    本地    | 可序列化 | [Python 支持](https://python.langchain.com/docs/integrations/document_loaders/firecrawl) |
| :--------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------- | :------: | :--: | :------------------------------------------------------------------------------------: |
| [`FireCrawlLoader`](https://reference.langchain.com/javascript/langchain-community/document_loaders/web/firecrawl/FireCrawlLoader) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) | 🟠（详见下文） |  测试版 |                                            ✅                                           |

### 加载器特性

|         来源        | Web 加载器 | 仅限 Node 环境 |
| :---------------: | :-----: | :--------: |
| `FireCrawlLoader` |    ✅    |      ❌     |

[FireCrawl](https://firecrawl.dev) 可以爬取并将任何网站转换为 LLM 就绪数据。它会爬取所有可访问的子页面，并为你提供每个页面的干净 Markdown 和元数据。无需站点地图。

FireCrawl 能够处理反向代理、缓存、速率限制以及被 JavaScript 阻止的内容等复杂任务。由 [mendable.ai](https://mendable.ai) 团队构建。

本指南展示了如何使用 LangChain 中的 `FireCrawlLoader` 来抓取和爬取整个网站并加载它们。

## 设置

要访问 `FireCrawlLoader` 文档加载器，你需要安装 `@langchain/community` 集成包和 `@mendable/firecrawl-js@0.0.36` 包。然后创建一个 **[FireCrawl](https://firecrawl.dev)** 账户并获取 API 密钥。

### 凭证

注册并获取你的免费 [FireCrawl API 密钥](https://firecrawl.dev) 以开始使用。FireCrawl 提供 300 个免费积分供你入门，并且它是[开源的](https://github.com/mendableai/firecrawl)，如果你想自托管的话。

完成此操作后，设置 `FIRECRAWL_API_KEY` 环境变量：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export FIRECRAWL_API_KEY="your-api-key"
```

如果你想获得模型调用的自动跟踪，也可以取消注释以下内容来设置你的 [LangSmith](/langsmith/home) API 密钥：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### 安装

LangChain FireCrawlLoader 集成位于 `@langchain/community` 包中：

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/community @langchain/core @mendable/firecrawl-js@0.0.36
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/community @langchain/core @mendable/firecrawl-js@0.0.36
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/community @langchain/core @mendable/firecrawl-js@0.0.36
  ```
</CodeGroup>

## 实例化

以下是使用 `FireCrawlLoader` 加载网页搜索结果的示例：

Firecrawl 提供 3 种模式：`scrape`、`crawl` 和 `map`。在 `scrape` 模式下，Firecrawl 将只抓取你提供的页面。在 `crawl` 模式下，Firecrawl 将爬取整个网站。在 `map` 模式下，Firecrawl 将返回与该网站相关的语义链接。

`formats`（对于 `crawl` 模式是 `scrapeOptions.formats`）参数允许从 `"markdown"`、`"html"` 或 `"rawHtml"` 中选择。但是，加载的文档将仅以一种格式返回内容，优先级如下：`markdown`，然后是 `html`，最后是 `rawHtml`。

现在我们可以实例化我们的模型对象并加载文档：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import "@mendable/firecrawl-js";
import { FireCrawlLoader } from "@langchain/community/document_loaders/web/firecrawl"

const loader = new FireCrawlLoader({
  url: "https://firecrawl.dev", // 要抓取的 URL
  apiKey: "...", // 可选，默认为你的环境变量中的 `FIRECRAWL_API_KEY`。
  mode: "scrape", // 运行爬虫的模式。可以是 "scrape" 用于单个 URL，或 "crawl" 用于所有可访问的子页面
  params: {
    // 基于 Firecrawl API 文档的可选参数
    // API 文档请访问 https://docs.firecrawl.dev
  },
})
```

## 加载

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const docs = await loader.load()
docs[0]
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
Document {
  pageContent: "Introducing [Smart Crawl!](https://www.firecrawl.dev/smart-crawl)\n" +
    " Join the waitlist to turn any web"... 18721 more characters,
  metadata: {
    title: "Home - Firecrawl",
    description: "Firecrawl crawls and converts any website into clean markdown.",
    keywords: "Firecrawl,Markdown,Data,Mendable,LangChain",
    robots: "follow, index",
    ogTitle: "Firecrawl",
    ogDescription: "Turn any website into LLM-ready data.",
    ogUrl: "https://www.firecrawl.dev/",
    ogImage: "https://www.firecrawl.dev/og.png?123",
    ogLocaleAlternate: [],
    ogSiteName: "Firecrawl",
    sourceURL: "https://firecrawl.dev",
    pageStatusCode: 500
  },
  id: undefined
}
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
console.log(docs[0].metadata)
```

```javascript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  title: "Home - Firecrawl",
  description: "Firecrawl crawls and converts any website into clean markdown.",
  keywords: "Firecrawl,Markdown,Data,Mendable,LangChain",
  robots: "follow, index",
  ogTitle: "Firecrawl",
  ogDescription: "Turn any website into LLM-ready data.",
  ogUrl: "https://www.firecrawl.dev/",
  ogImage: "https://www.firecrawl.dev/og.png?123",
  ogLocaleAlternate: [],
  ogSiteName: "Firecrawl",
  sourceURL: "https://firecrawl.dev",
  pageStatusCode: 500
}
```

## 附加参数

对于 `params`，你可以根据 [Firecrawl 文档](https://docs.firecrawl.dev) 传递任何参数。

***

## API 参考

有关所有 `FireCrawlLoader` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-community/document_loaders/web/firecrawl/FireCrawlLoader)。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs) 通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/document_loaders/web_loaders/firecrawl.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
