跳到主要内容
本笔记本提供了使用 FireCrawlLoader 的快速入门概览。有关所有 FireCrawlLoader 功能和配置的详细文档,请查阅 API 参考

概览

集成详情

类别本地可序列化PY 支持
FireCrawlLoader@langchain/community🟠(详见下文)测试版

加载器功能

来源网页加载器仅限 Node 环境
FireCrawlLoader
FireCrawl 抓取并将任何网站转换为可供 LLM 使用的数据。它会抓取所有可访问的子页面,并为您提供干净的 Markdown 和元数据。无需站点地图。 FireCrawl 处理复杂的任务,例如反向代理、缓存、速率限制和被 JavaScript 阻止的内容。由 mendable.ai 团队构建。 本指南演示了如何抓取和爬取整个网站,并使用 LangChain 中的 FireCrawlLoader 加载它们。

设置

要访问 FireCrawlLoader 文档加载器,您需要安装 @langchain/community 集成和 @mendable/firecrawl-js@0.0.36 包。然后创建一个 FireCrawl 账户并获取 API 密钥。

凭据

注册并获取您的免费 FireCrawl API 密钥 以开始使用。FireCrawl 提供 300 个免费积分供您入门,如果您想自托管,它是 开源的 完成此操作后,设置 FIRECRAWL_API_KEY 环境变量:
export FIRECRAWL_API_KEY="your-api-key"
如果您想获取模型调用的自动化跟踪,您还可以通过取消注释下方来设置您的 LangSmith API 密钥
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

安装

LangChain FireCrawlLoader 集成位于 @langchain/community 包中
npm install @langchain/community @langchain/core @mendable/firecrawl-js@0.0.36

实例化

以下是如何使用 FireCrawlLoader 加载网页搜索结果的示例: Firecrawl 提供 3 种模式:scrapecrawlmap。在 scrape 模式下,Firecrawl 将仅抓取您提供的页面。在 crawl 模式下,Firecrawl 将爬取整个网站。在 map 模式下,Firecrawl 将返回与网站相关的语义链接。 formats (crawl 模式下的 scrapeOptions.formats) 参数允许从 "markdown""html""rawHtml" 中进行选择。然而,加载的文档将只返回一种格式的内容,优先级如下:markdown,然后是 html,最后是 rawHtml 现在我们可以实例化我们的模型对象并加载文档:
import "@mendable/firecrawl-js";
import { FireCrawlLoader } from "@langchain/community/document_loaders/web/firecrawl"

const loader = new FireCrawlLoader({
  url: "https://firecrawl.dev", // The URL to scrape
  apiKey: "...", // Optional, defaults to `FIRECRAWL_API_KEY` in your env.
  mode: "scrape", // The mode to run the crawler in. Can be "scrape" for single urls or "crawl" for all accessible subpages
  params: {
    // optional parameters based on Firecrawl API docs
    // For API documentation, visit https://docs.firecrawl.dev
  },
})

加载

const docs = await loader.load()
docs[0]
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
}
console.log(docs[0].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
}

额外参数

对于 params,您可以根据 Firecrawl 文档 传递任何参数。

API 参考

有关所有 FireCrawlLoader 功能和配置的详细文档,请查阅 API 参考
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.