What is WebBaseLoader?
WebBaseLoader is one of the simplest document loaders in the langchain-community package. It uses Python requests to fetch one or more URLs and then BeautifulSoup4 to parse the HTML and extract text content. The resulting Document objects contain the raw text in page_content and a metadata dict with the source URL. Because it runs synchronous HTTP requests, WebBaseLoader is most appropriate for small-scale ingestion: loading documentation pages, blog posts, or landing pages into a RAG pipeline.
Under the hood, WebBaseLoader respects standard HTTP headers and you can pass custom header_template and requests_kwargs to control User-Agent strings, authentication tokens, or proxy settings. It does not render JavaScript — pages that load content dynamically via React, Vue, or Next.js will return empty or partial page_content. For JavaScript-rendered pages, the correct alternative is FireCrawlLoader (cloud-based) or PlaywrightURLLoader (headless browser, local).
The web_paths parameter accepts a single URL string or a list. When multiple URLs are provided, load() fetches them sequentially. For concurrent fetching, use aload() which fires all requests concurrently using aiohttp and can dramatically reduce wall-clock time for large URL lists. The bs_kwargs parameter accepts BeautifulSoup options like SoupStrainer to extract only specific HTML elements, reducing noise in the extracted text.
When to Use
You need to index web pages or documentation. Use WebBaseLoader for simple static websites.
Use Cases
- • Index documentation
- • Scrape static websites
- • Research collection
- • Content aggregation
- • Web-based RAG
- • Documentation indexing
Key Features
- ✓ Simple HTML parsing
- ✓ Text extraction
- ✓ No JavaScript support
- ✓ BeautifulSoup-based
- ✓ Batch loading
- ✓ Metadata
When NOT to Use
For JavaScript-heavy sites—use FireCrawl. For large-scale scraping.
Notes
No JavaScript rendering
The most common production failure: page_content comes back mostly empty or contains only navigation text because the page is JavaScript-rendered. Check early with len(doc.page_content) < 200. Switch to FireCrawlLoader (cloud) or PlaywrightURLLoader (local headless browser) for JS-heavy sites.
BeautifulSoup4 and lxml must be installed
langchain-community lists beautifulsoup4 as an optional dependency. Run pip show beautifulsoup4 to confirm it is present. Also install lxml for faster HTML parsing and pass bs_kwargs={"features": "lxml"} to the loader.
Rate limiting and robots.txt
WebBaseLoader does not respect robots.txt or add delays between requests. For multiple pages from the same domain, add time.sleep() between calls or use a proper scraping framework to avoid 429 errors and IP bans.
metadata source records the original URL
Redirects are followed automatically by requests, but doc.metadata['source'] records the original URL you passed, not the final redirected URL. Keep this in mind when citing sources or filtering by URL prefix in retrieval.
Import
from langchain_community.document_loaders import WebBaseLoader
Key Parameters
| Parameter | Type | Default | Purpose |
|---|---|---|---|
| web_paths | List[str]|str | None | URLs to load |
Usage Examples
Load single page
loader = WebBaseLoader('https://docs.example.com/intro')
docs = loader.load()
for doc in docs:
print(doc.page_content[:100])
Batch load with SoupStrainer to filter noise
from langchain_community.document_loaders import WebBaseLoader
from bs4 import SoupStrainer
urls = [
'https://docs.langchain.com/docs/introduction',
'https://docs.langchain.com/docs/get-started',
'https://docs.langchain.com/docs/use-cases',
]
loader = WebBaseLoader(
web_paths=urls,
bs_kwargs={'parse_only': SoupStrainer('article')},
)
docs = loader.load()
print(f'Loaded {len(docs)} pages')
Async concurrent loading with aload()
import asyncio
from langchain_community.document_loaders import WebBaseLoader
urls = [f'https://docs.example.com/page-{i}' for i in range(20)]
loader = WebBaseLoader(web_paths=urls)
async def load_all():
return await loader.aload()
docs = asyncio.run(load_all())
print(f'Loaded {len(docs)} pages concurrently')
Common Mistakes
❌ Expect JavaScript rendering
✅ Use FireCrawlLoader for JS-heavy sites
Related LangChain References
Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with WebBaseLoader and the wider framework.
WebBaseLoader FAQ
What is WebBaseLoader in LangChain?
Load web pages as documents. WebBaseLoader is one of the simplest document loaders in the langchain-community package. It uses Python requests to fetch one or more URLs and then BeautifulSoup4 to parse the HTML and extract text content. The resulting Document objects contain the raw text in page_content and a metadata dict with the source URL. Because it runs synchronous HTTP requests, WebBaseLoader is most appropriate for small-scale ingestion: loading documentation pages, blog posts, or landing pages i…
Which package provides WebBaseLoader?
DevShelfHub documents WebBaseLoader from the langchain-community package. Pin your installed LangChain version and match imports to the snippet on this page.
When should I use WebBaseLoader?
You need to index web pages or documentation. Use WebBaseLoader for simple static websites.
When should I avoid using WebBaseLoader?
For JavaScript-heavy sites—use FireCrawl. For large-scale scraping.
How do I import WebBaseLoader in Python?
from langchain_community.document_loaders import WebBaseLoader
Where can I explore more LangChain API reference pages?
Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.