Sitemap · Python
Discover URLs from a sitemap or use them to seed a bounded crawl.
In this guide
Purpose and lifecycle
listUrls/list_urls returns an in-memory list of sitemap entries. It does not fetch each listed page.
maxDepth/max_depth limits sitemap-index recursion. depth limits subsequent crawling from each seed; these limits have different meanings.
For a large dataset, persist discovered URLs to a file and use DatasetJob. Inspect gzip and child-sitemap handling for your binding before relying on compressed sitemap support.
Definition and availability
Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.
Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.
class SitemapUsage example
Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.
from crawlingo import Sitemap
entries = Sitemap("https://example.com/sitemap.xml").max_depth(3).list_urls()
with open("urls.txt", "w", encoding="utf-8") as out:
for entry in entries:
out.write(entry.loc + "\n")Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| __init__ | method | Not annotated; see behavior notes | Present in source |
| max_depth | method | 'Sitemap' | Present in source |
| follow | method | 'Sitemap' | Present in source |
| limit | method | 'Sitemap' | Present in source |
| depth | method | 'Sitemap' | Present in source |
| concurrency | method | 'Sitemap' | Present in source |
| delay | method | 'Sitemap' | Present in source |
| field | method | 'Sitemap' | Present in source |
| webhook | method | 'Sitemap' | Present in source |
| list_urls | method | List[SitemapEntry] | Present in source |
| build | method | CrawlResults | Present in source |
__init__()
Create a sitemap discovery builder. Fetching begins with listUrls/list_urls or build; the constructor does not materialize discovered URLs.
Returns / value: Not annotated; see behavior notes.
def __init__(self, sitemap_url: str, *, session: Optional[Session]=None)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| sitemap_url | str | Required | URL of a sitemap XML document or index. |
| session | Optional[Session] | Default: None | Shared request state. Omit only where the signature provides a default. |
max_depth()
Maximum sitemap-index nesting depth.
Returns / value: 'Sitemap'.
def max_depth(self, depth: int) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| depth | int | Required | Nesting or crawl-hop limit, as specified by this method. |
follow()
Configure links followed after a seed page is fetched.
Returns / value: 'Sitemap'.
def follow(self, selector: str) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| selector | str | Required | Selector evaluated against the fetched DOM. |
limit()
Configure the downstream crawl page limit.
Returns / value: 'Sitemap'.
def limit(self, pages: int) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| pages | int | Required | Maximum downstream crawl pages. |
depth()
Configure the downstream crawl hop limit.
Returns / value: 'Sitemap'.
def depth(self, max_depth: int) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| max_depth | int | Required | Maximum sitemap nesting or crawl depth, according to the API. |
concurrency()
Configure concurrent downstream crawl workers.
Returns / value: 'Sitemap'.
def concurrency(self, n: int) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| n | int | Required | Count or index; see the method description. |
delay()
Configure downstream crawl delay in seconds.
Returns / value: 'Sitemap'.
def delay(self, seconds: float) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| seconds | float | Required | Time in seconds; see the method-specific range and timing semantics. |
field()
Add a downstream extraction field.
Returns / value: 'Sitemap'.
def field(self, name: str, selector: str, selector_type: str='css', default: Optional[str]=None) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| name | str | Required | Field, header or attribute name for this operation. |
| selector | str | Required | Selector evaluated against the fetched DOM. |
| selector_type | str | Default: 'css' | Selector engine for this field; supported values differ between builders. |
| default | Optional[str] | Default: None | Fallback field value when extraction is empty. |
webhook()
Set a downstream result endpoint; delivery is not durable.
Returns / value: 'Sitemap'.
def webhook(self, url: str) -> 'Sitemap'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | str | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
list_urls()
Fetch sitemap documents and return discovered URL entries; results are collected in memory.
Returns / value: List[SitemapEntry].
def list_urls(self) -> List[SitemapEntry]build()
Seed a crawl with sitemap URLs and return its in-memory results.
Returns / value: CrawlResults.
def build(self) -> CrawlResultsErrors and operational limits
Node listUrls now propagates fetch/parse errors. Python list_urls can skip failing sitemap fetches in its native binding. Empty results can therefore have different meanings.
Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.