WebBaseLoader, SitemapLoader loads a sitemap from a given URL, and then scrapes and loads all pages in the sitemap, returning each page as a Document.
The scraping is done concurrently. There are reasonable limits to concurrent requests, defaulting to 2 per second. If you aren’t concerned about being a good citizen, or you control the scrapped server, or don’t care about load you can increase this limit. Note, while this will speed up the scraping process, it may cause the server to block you. Be careful!
概述
集成详情
加载器特性
设置
To access SiteMap document loader you’ll need to install thelangchain-community integration package.
凭证
No credentials are needed to run this. 要启用模型调用的自动追踪,请设置你的 LangSmith API 密钥:安装
安装 langchain-community。Fix notebook asyncio bug
初始化
现在我们可以实例化模型对象并加载文档:加载
requests_per_second parameter to increase the max concurrent requests. and use requests_kwargs to pass kwargs when send requests.
惰性加载
You can also load the pages lazily in order to minimize the memory load.Filtering sitemap URLs
Sitemaps can be massive files, with thousands of URLs. Often you don’t need every single one of them. You can filter the URLs by passing a list of strings or regex patterns to thefilter_urls parameter. Only URLs that match one of the patterns will be loaded.
Add custom scraping rules
TheSitemapLoader uses beautifulsoup4 for the scraping process, and it scrapes every element on the page by default. The SitemapLoader constructor accepts a custom scraping function. This feature can be helpful to tailor the scraping process to your specific needs; for example, you might want to avoid scraping headers or navigation elements.
以下example shows how to develop and use a custom function to avoid navigation and header elements.
Import the beautifulsoup4 library and define the custom function.
SitemapLoader object.
Local sitemap
The sitemap loader can also be used to load local files.API 参考
For detailed documentation of allSiteMapLoader features and configurations head to the API reference
通过 MCP 将这些文档连接到 Claude、VSCode 等工具以获取实时答案。

