How to extract every URL from a website's XML sitemap
Discover a site's sitemaps from robots.txt, follow sitemap indexes and .xml.gz files, and export every URL with lastmod. Includes Python and JavaScript examples and per-URL pricing.
The complete list of a site’s public URLs, when the site publishes a sitemap, is in its XML sitemap files — not in a full HTML crawl. Give a domain or a sitemap URL to a sitemap reader, follow nested indexes and .xml.gz files, and you get every <loc> with lastmod, changefreq and priority when those fields exist. Apizap’s Sitemap URL Extractor does that for $0.25 per 1,000 URLs plus a $0.005 start fee, and it does not download the pages themselves.
Use this when you want a URL inventory for SEO, a list of docs to feed a crawler or a vector store, or a daily feed of only the URLs that appeared since the last run.
Where are sitemaps declared?
Start with https://example.com/robots.txt. Websites that follow common practice include one or more lines like:
Sitemap: https://example.com/sitemap.xml
If that line is missing, the file is often still at a well-known path: /sitemap.xml, /sitemap_index.xml, /sitemap.xml.gz, or a CMS-specific path such as /wp-sitemap.xml or /sitemap-index.xml. A sitemap index is a list of other sitemaps. Large sites split by section, by day or by language, and those child files may themselves be gzip-compressed.
The actor discovers sitemaps from robots.txt and from those common paths when you pass a domain or homepage. If you already know the sitemap URL, pass it directly and discovery is skipped for that input.
A sitemap reader is not a crawler. It will not find URLs that the site never put in a sitemap. Orphan pages, noindexed URLs omitted from the sitemap, and sites that simply do not publish one will not appear. In that case you need a crawl, or you need the site owner to add a sitemap.
What does each URL record contain?
Each dataset row is one URL:
url— the<loc>valuelastmod— if the sitemap provided onechangefreqandpriority— if present (many sites omit them; they are hints, not directives)imageCount— number of image entries under that URL, when the sitemap uses the image extensionsite— the hostsitemap— which sitemap file the URL came fromisNew— filled when you turn on “only URLs new since last run”extractedAt— when this run saw the URL
A SUMMARY record in the key-value store lists sitemap files read and how many URLs were read versus output per site, which is the first place to look if a count looks too small.
You can keep a subset with regex includePatterns / excludePatterns (for example only /blog/ or /docs/, and drop /tag/), and with lastmodAfter as a date (YYYY-MM-DD) or a relative window such as 7 days. URLs that have no lastmod are dropped when a lastmod filter is set, so do not use that filter if a site omits dates.
Step-by-step
1. Give a domain, or the sitemap URL if you already have it
For most sites, https://developer.mozilla.org or example.com is enough. If discovery finds nothing, open robots.txt yourself, copy the Sitemap: URL, and pass that.
2. Filter to the section you care about, and set a cap
Add include and exclude regexes before you pull a site with hundreds of thousands of URLs. Set maxItems (and maxUrlsPerSite if you pass several hosts) so a surprisingly large index cannot bill you for every product variant on the first try.
3. Run once for a full inventory, or on a schedule in monitor mode
A full extract is the baseline. For “what did they publish today?”, turn on onlyNewSinceLastRun and use the same actor and account on a schedule. Later runs output only URLs that were not seen before. If a monitor run finds nothing new, you pay only the start fee (and zero URL events).
4. Export the dataset and, if you need the pages themselves, crawl only that list
The extractor does not fetch page HTML. Feed the URL list into your own crawler, a RAG pipeline, or an SEO audit. That keeps sitemap reads cheap and avoids hitting the site once per URL just to learn the URL exists.
Working Python example
import os
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("apizap.com/sitemap-url-extractor").call(
run_input={
"startUrls": [
"https://developer.mozilla.org",
"https://blog.cloudflare.com/sitemap.xml",
],
"includePatterns": [],
"excludePatterns": ["/tag/"],
"lastmodAfter": "7 days",
"onlyNewSinceLastRun": False,
"maxItems": 10000,
}
)
urls = client.dataset(run["defaultDatasetId"]).list_items().items
print(f"{len(urls)} URLs")
for row in urls[:8]:
print(row["lastmod"], row["url"])
To keep only documentation paths, set "includePatterns": ["/docs/"]. To use the extract as a new-URL monitor, set "onlyNewSinceLastRun": True and schedule the same input daily.
Working JavaScript example
import { ApifyClient } from "apify-client";
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor("apizap.com/sitemap-url-extractor").call({
startUrls: ["https://developer.mozilla.org"],
excludePatterns: ["/tag/"],
lastmodAfter: "7 days",
onlyNewSinceLastRun: false,
maxItems: 10000,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(`${items.length} URLs`);
for (const row of items.slice(0, 8)) {
console.log(row.lastmod, row.url);
}
What does a run cost?
Pricing is $0.00025 per URL returned ($0.25 per 1,000) plus $0.005 per run. You are charged for URLs that remain after your regex and lastmod filters, not for every <loc> in the raw files. Monitor runs that return no new URLs cost $0.005.
| URLs returned | Start fee | URL events | Total |
|---|---|---|---|
| 0 (monitor, nothing new) | $0.005 | $0 | $0.005 |
| 100 | $0.005 | $0.025 | $0.030 |
| 1,000 | $0.005 | $0.25 | $0.255 |
| 5,000 | $0.005 | $1.25 | $1.255 |
| 50,000 | $0.005 | $12.50 | $12.505 |
A weekly inventory of a 5,000-URL docs site is about $1.26. A daily monitor on the same site that usually adds a handful of posts is a few cents on busy days and half a cent on quiet ones.
maxItems defaults to 10,000 in the input schema. Raise or lower it on purpose. Set it to 0 only when you are sure you want the entire index and you have accepted the cost.
Sitemap extract versus a full crawl
| Sitemap extract | HTML crawl | |
|---|---|---|
| What you get | URLs the site chose to list, plus lastmod when present | Pages the crawler can reach by following links |
| Load on the site | A few sitemap file downloads | One request per page |
| Hidden / orphan URLs | Missed if they are not in the sitemap | May still be missed if unlinked |
| Best for | Inventories, change monitoring, seed lists | Content extraction, link graphs, rendering |
Most SEO and RAG jobs should start with the sitemap, then crawl or audit only the URLs they need. After you have the list, the SEO & AI Search Readiness Audit can score a sample of those pages for on-page and crawler-access issues.
FAQ
The actor says no sitemap was found. What next?
Open /robots.txt and try common paths yourself. If the site has no sitemap, this tool cannot invent one. Some sites only publish a sitemap on a subdomain or behind a locale prefix — pass that URL directly.
Does this download every page on the site?
No. It only reads sitemap files (including nested indexes and .xml.gz). That is why it is inexpensive and light on the target host.
Why did lastmod filters drop so many URLs?
If you set lastmodAfter, URLs without a lastmod are excluded. Many sitemaps omit dates. Clear the filter to keep those URLs, or inspect a sample row first.
Can I use this to watch a competitor’s new posts or products?
Yes, if those URLs appear in their sitemap. Schedule a run with onlyNewSinceLastRun set to true. You will get new <loc> values, not the page content, and only for URLs the competitor chose to list.
Are changefreq and priority reliable?
They are optional hints from the site owner. Search engines may ignore them. Useful when present, safe to treat as missing when they are null.
Sitemap URL Extractor on Apify StoreTool pageSEO & AI Search Readiness Audit on Apify StoreTool page