Skip to main content
The RecursiveUrlLoader lets you recursively scrape all child links from a root URL and parse them into Documents.

概述

集成详情

加载器特性

设置

凭证

No credentials are required to use the RecursiveUrlLoader.

安装

The RecursiveUrlLoader lives in the langchain-community package. There’s no other required packages, though you will get richer default Document metadata if you have “beautifulsoup4` installed as well.

Instantiation

Now we can instantiate our document loader object and load Documents:

加载

Use .load() to synchronously load into memory all Documents, with one Document per visited URL. Starting from the initial URL, we recurse through all linked URLs up to the specified max_depth. Let’s run through a basic example of how to use the RecursiveUrlLoader on the Python 3.9 Documentation.
Great! The first document looks like the root page we started from. Let’s look at the metadata of the next document
That url looks like a child of our root page, which is great! Let’s move on from metadata to examine the content of one of our documents
That certainly looks like HTML that comes from the url docs.python.org/3.9/, which is what we expected. Let’s now look at some variations we can make to our basic example that can be helpful in different situations.

Lazy loading

如果我们加载大量文档,且下游操作可以在所有已加载文档的子集上完成,我们可以一次惰性加载一个文档以最小化内存占用:
在此示例中,我们在任何时候内存中加载的文档不会超过 10 个。

Adding an extractor

默认情况下,the loader sets the raw HTML from each link as the Document page content. To parse this HTML into a more human/LLM-friendly format you can pass in a custom extractor method:
This looks much nicer! You can similarly pass in a metadata_extractor to customize how Document metadata is extracted from the HTTP response. See the API reference for more on this.

API 参考

These examples show just a few of the ways in which you can modify the default RecursiveUrlLoader, but there are many more modifications that can be made to best fit your use case. Using the parameters link_regex and exclude_dirs can help you filter out unwanted URLs, aload() and alazy_load() can be used for asynchronous loading, and more. For detailed information on configuring and calling the RecursiveUrlLoader, please see the API reference.