# SitemapLoader

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/document_loaders/sitemap/SitemapLoader)

Load a sitemap and its URLs.

**Security Note**: This loader can be used to load all URLs specified in a sitemap.
    If a malicious actor gets access to the sitemap, they could force
    the server to load URLs from other domains by modifying the sitemap.
    This could lead to server-side request forgery (SSRF) attacks; e.g.,
    with the attacker forcing the server to load URLs from internal
    service endpoints that are not publicly accessible. While the attacker
    may not immediately gain access to this data, this data could leak
    into downstream systems (e.g., data loader is used to load data for indexing).

    This loader is a crawler and web crawlers should generally NOT be deployed
    with network access to any internal servers.

    Control access to who can submit crawling requests and what network access
    the crawler has.

    By default, the loader will only load URLs from the same domain as the sitemap
    if the site map is not a local file. This can be disabled by setting
    restrict_to_same_domain to False (not recommended).

    If the site map is a local file, no such risk mitigation is applied by default.

    Use the filter URLs argument to limit which URLs can be loaded.

    See https://python.langchain.com/docs/security

## Signature

```python
SitemapLoader(
    self,
    web_path: str,
    filter_urls: Optional[List[str]] = None,
    parsing_function: Optional[Callable] = None,
    blocksize: Optional[int] = None,
    blocknum: int = 0,
    meta_function: Optional[Callable] = None,
    is_local: bool = False,
    continue_on_failure: bool = False,
    restrict_to_same_domain: bool = True,
    max_depth: int = 10,
    **kwargs: Any = {},
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `web_path` | `str` | Yes | url of the sitemap. can also be a local path |
| `filter_urls` | `Optional[List[str]]` | No | a list of regexes. If specified, only URLS that match one of the filter URLs will be loaded. *WARNING* The filter URLs are interpreted as regular expressions. Remember to escape special characters if you do not want them to be interpreted as regular expression syntax. For example, `.` appears frequently in URLs and should be escaped if you want to match a literal `.` rather than any character. restrict_to_same_domain takes precedence over filter_urls when restrict_to_same_domain is True and the sitemap is not a local file. (default: `None`) |
| `parsing_function` | `Optional[Callable]` | No | Function to parse bs4.Soup output (default: `None`) |
| `blocksize` | `Optional[int]` | No | number of sitemap locations per block (default: `None`) |
| `blocknum` | `int` | No | the number of the block that should be loaded - zero indexed. Default: 0 (default: `0`) |
| `meta_function` | `Optional[Callable]` | No | Function to parse bs4.Soup output for metadata remember when setting this method to also copy metadata["loc"] to metadata["source"] if you are using this field (default: `None`) |
| `is_local` | `bool` | No | whether the sitemap is a local file. Default: False (default: `False`) |
| `continue_on_failure` | `bool` | No | whether to continue loading the sitemap if an error occurs loading a url, emitting a warning instead of raising an exception. Setting this to True makes the loader more robust, but also may result in missing data. Default: False (default: `False`) |
| `restrict_to_same_domain` | `bool` | No | whether to restrict loading to URLs to the same domain as the sitemap. Attention: This is only applied if the sitemap is not a local file! (default: `True`) |
| `max_depth` | `int` | No | maximum depth to follow sitemap links. Default: 10 (default: `10`) |

## Extends

- `WebBaseLoader`

## Constructors

```python
__init__(
    self,
    web_path: str,
    filter_urls: Optional[List[str]] = None,
    parsing_function: Optional[Callable] = None,
    blocksize: Optional[int] = None,
    blocknum: int = 0,
    meta_function: Optional[Callable] = None,
    is_local: bool = False,
    continue_on_failure: bool = False,
    restrict_to_same_domain: bool = True,
    max_depth: int = 10,
    **kwargs: Any = {},
)
```

| Name | Type |
|------|------|
| `web_path` | `str` |
| `filter_urls` | `Optional[List[str]]` |
| `parsing_function` | `Optional[Callable]` |
| `blocksize` | `Optional[int]` |
| `blocknum` | `int` |
| `meta_function` | `Optional[Callable]` |
| `is_local` | `bool` |
| `continue_on_failure` | `bool` |
| `restrict_to_same_domain` | `bool` |
| `max_depth` | `int` |


## Properties

- `allow_url_patterns`
- `restrict_to_same_domain`
- `parsing_function`
- `meta_function`
- `blocksize`
- `blocknum`
- `is_local`
- `continue_on_failure`
- `max_depth`

## Methods

- [`parse_sitemap()`](https://reference.langchain.com/python/langchain-community/document_loaders/sitemap/SitemapLoader/parse_sitemap)
- [`lazy_load()`](https://reference.langchain.com/python/langchain-community/document_loaders/sitemap/SitemapLoader/lazy_load)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/a6a6079511ac8a5c1293337f88096b8641562e77/libs/community/langchain_community/document_loaders/sitemap.py#L48)