Skip to main content

GitBook

本示例介绍如何使用 Cheerio 从任何 GitBook 加载数据。将为每个页面创建一个文档。

¥This example goes over how to load data from any GitBook, using Cheerio. One document will be created for each page.

设置

¥Setup

npm install @langchain/community @langchain/core cheerio

从单个 GitBook 页面加载

¥Load from single GitBook page

import { GitbookLoader } from "@langchain/community/document_loaders/web/gitbook";

const loader = new GitbookLoader(
"https://docs.gitbook.com/product-tour/navigation"
);

const docs = await loader.load();

从给定 GitBook 中的所有路径加载

¥Load from all paths in a given GitBook

为了使其正常工作,需要使用根路径(本例中为 https://docs.gitbook.com)初始化 GitbookLoader,并将 shouldLoadAllPaths 设置为 true

¥For this to work, the GitbookLoader needs to be initialized with the root path (https://docs.gitbook.com in this example) and have shouldLoadAllPaths set to true.

import { GitbookLoader } from "@langchain/community/document_loaders/web/gitbook";

const loader = new GitbookLoader("https://docs.gitbook.com", {
shouldLoadAllPaths: true,
});

const docs = await loader.load();