Sitemap · Node.js
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.
export 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.
import { Sitemap } from 'crawlingo';
import { writeFileSync } from 'node:fs';
const entries = await new Sitemap('https://example.com/sitemap.xml').maxDepth(3).listUrls();
writeFileSync('urls.txt', entries.map(entry => entry.loc).join('\n') + '\n');Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| constructor | method | Sitemap | Present in source |
| maxDepth | method | this | Present in source |
| follow | method | this | Present in source |
| limit | method | this | Present in source |
| depth | method | this | Present in source |
| concurrency | method | this | Present in source |
| delay | method | this | Present in source |
| field | method | this | Present in source |
| webhook | method | this | Present in source |
| listUrls | method | Promise<SitemapEntry[]> | Present in source |
| build | method | Promise<DatasetResult[]> | Present in source |
constructor()
Create a sitemap discovery builder. Fetching begins with listUrls/list_urls or build; the constructor does not materialize discovered URLs.
Returns / value: Sitemap.
constructor(sitemapUrl: string, opts?: { session?: Session; }): Sitemap| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| sitemapUrl | string | Required | URL of a sitemap XML document or index. |
| opts | { session?: Session; } | Default: {} | Optional extraction settings; use only the keys declared by this method. |
maxDepth()
Maximum sitemap-index nesting depth.
Returns / value: this.
maxDepth(depth: number): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| depth | number | Required | Nesting or crawl-hop limit, as specified by this method. |
follow()
Configure links followed after a seed page is fetched.
Returns / value: this.
follow(selector: string): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| selector | string | Required | Selector evaluated against the fetched DOM. |
limit()
Configure the downstream crawl page limit.
Returns / value: this.
limit(pages: number): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| pages | number | Required | Maximum downstream crawl pages. |
depth()
Configure the downstream crawl hop limit.
Returns / value: this.
depth(maxDepth: number): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| maxDepth | number | Required | Maximum sitemap nesting or crawl depth, according to the API. |
concurrency()
Configure concurrent downstream crawl workers.
Returns / value: this.
concurrency(n: number): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| n | number | Required | Count or index; see the method description. |
delay()
Configure downstream crawl delay in seconds.
Returns / value: this.
delay(seconds: number): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| seconds | number | Required | Time in seconds; see the method-specific range and timing semantics. |
field()
Add a downstream extraction field.
Returns / value: this.
field(name: string, selector: string, selectorType?: string, defaultValue?: string): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| name | string | Required | Field, header or attribute name for this operation. |
| selector | string | Required | Selector evaluated against the fetched DOM. |
| selectorType | string | Default: 'css' | Selector engine for this field; supported values differ between builders. |
| defaultValue | string | undefined | Optional | Fallback string when extraction produces no value. |
webhook()
Set a downstream result endpoint; delivery is not durable.
Returns / value: this.
webhook(url: string): this| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | string | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
listUrls()
Fetch sitemap documents and return discovered URL entries; results are collected in memory.
Returns / value: Promise<SitemapEntry[]>.
listUrls(): Promise<SitemapEntry[]>build()
Seed a crawl with sitemap URLs and return its in-memory results.
Returns / value: Promise<DatasetResult[]>.
build(): Promise<DatasetResult[]>Errors 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.