{"slug": "sitemap-xml-vs-website-mapping-vs-crawling", "title": "Sitemap.xml vs website mapping vs crawling", "summary": "A Spidra technical guide lays out a decision tree for choosing between reading a sitemap.xml file, mapping a site's URLs, and crawling its pages, noting that sitemap reading is free via one request per file while mapping costs 1 credit per map and crawling costs 1 credit per page returned. The guide includes a Python parser that reads Sitemap lines from robots.txt, falls back to /sitemap.xml and /sitemap_index.xml, follows index files, decompresses gzip, and caps child sitemaps with a max_children setting. It recommends sitemaps when only published URLs are needed, mapping when the sitemap is insufficient, and crawling when page content is required.", "body_md": "You need the pages of a website, but you don't know its URLs yet. On sitemap vs crawl, the short answer is this. Read the sitemap when you only need the URLs a site chooses to publish. Use Map when you need the site's URLs and the sitemap isn't enough. Use [Crawl](https://spidra.io/ai-crawler) when you need the pages themselves and can describe them. This post gives you a decision tree, and shows what each method returns on real sites with code you can repeat.\n\n## What each method gives you\n\nAll three discover pages, but they answer different questions:\n\n|  | Sitemap.xml | Map | Crawl | \n|---|---|---|---|\n| Finds | The URLs the site chooses to list | URLs from the sitemap and from the site's links | Pages that match a description, found by following links | \n| Returns | URLs, sometimes dates | URLs with the link text they were found under | Each page's content as Markdown, and extracted data if you ask | \n| Reads page content | No | No | Yes | \n| Cost | Free, your own requests | 1 credit per map | 1 credit per page returned | \n\n## Read the sitemap yourself\n\nA sitemap is a file the site publishes, so reading it is free and takes one request per file. The parser below reads the `Sitemap:` lines in robots.txt, falls back to `/sitemap.xml` and `/sitemap_index.xml`, follows index files and decompresses gzip. `max_children` caps how many child files it opens from an index. Install `requests` and start with the file handling:\n\n``` python\n# sitemap_urls.py\nimport gzip\nimport re\nimport xml.etree.ElementTree as ET\nfrom dataclasses import dataclass, field\n\nimport requests\n\nHEADERS = {\"User-Agent\": \"sitemap-reader (research script)\"}\n\ndef fetch(url):\n    response = requests.get(url, headers=HEADERS, timeout=30)\n    response.raise_for_status()\n    body = response.content\n    return gzip.decompress(body) if body[:2] == b\"\\x1f\\x8b\" else body\n\n@dataclass\nclass Sitemaps:\n    urls: list = field(default_factory=list)       # (url, lastmod or None)\n    read: int = 0                                  # sitemap files fetched\n    skipped: int = 0                               # child sitemaps left unread because of max_children\n    problems: list = field(default_factory=list)   # files that failed, with the reason\n\ndef locations(site, get=fetch):\n    \"\"\"Sitemap files the site announces in robots.txt, else the two usual paths. Returns (urls, announced).\"\"\"\n    try:\n        robots = get(f\"{site}/robots.txt\").decode(\"utf-8\", \"replace\")\n        found = re.findall(r\"(?im)^\\s*sitemap:\\s*(\\S+)\", robots)\n    except Exception:\n        found = []\n    return (found, True) if found else ([f\"{site}/sitemap.xml\", f\"{site}/sitemap_index.xml\"], False)\n```\n\n`sitemap_urls()` walks the files, keeps every `<loc>` and records files that fail without stopping:\n\n``` python\ndef sitemap_urls(site, max_children=None, get=fetch):\n    \"\"\"Every <loc> in the site's sitemap files, following indexes and gzip. Never raises on one bad file.\"\"\"\n    result, seen = Sitemaps(), set()\n    queue, announced = locations(site, get)\n    guesses = set() if announced else set(queue)    # a missing guess is not a problem\n    children = 0\n    while queue:\n        url = queue.pop(0)\n        if url in seen:\n            continue\n        seen.add(url)\n        try:\n            root = ET.fromstring(get(url))\n        except Exception as error:\n            if url not in guesses:\n                result.problems.append(f\"{url}: {error}\")\n            continue\n        result.read += 1\n        kind = root.tag.rsplit(\"}\", 1)[-1]\n        for node in root:\n            loc = node.findtext(\"{*}loc\")\n            if not loc:\n                continue\n            if kind == \"sitemapindex\":\n                if max_children is not None and children >= max_children:\n                    result.skipped += 1\n                else:\n                    children += 1\n                    queue.append(loc.strip())\n            else:\n                result.urls.append((loc.strip(), node.findtext(\"{*}lastmod\")))\n    if not result.read and not result.problems:\n        result.problems.append(\"no sitemap found\")\n    return result\n```\n\nRun it on three sites. `yarnpkg.com` and `github.com` publish one file each, and `pypi.org` publishes an index of child files, so the run opens only the first two:\n\n``` python\nimport time\n\nfrom sitemap_urls import sitemap_urls\n\nfor site, children in ((\"https://yarnpkg.com\", None), (\"https://github.com\", None), (\"https://pypi.org\", 2)):\n    start = time.perf_counter()\n    found = sitemap_urls(site, max_children=children)\n    seconds = time.perf_counter() - start\n    dated = sum(1 for _, lastmod in found.urls if lastmod)\n    print(f\"{site} | {len(found.urls)} URLs | {found.read} files read, {found.skipped} left unread | \"\n          f\"{dated} with lastmod | {seconds:.1f}s | problems: {found.problems or 'none'}\")\n```\n\nOutput:\n\n```\nhttps://yarnpkg.com | 407 URLs | 1 files read, 0 left unread | 0 with lastmod | 0.6s | problems: none\nhttps://github.com | 376 URLs | 1 files read, 0 left unread | 0 with lastmod | 0.4s | problems: none\nhttps://pypi.org | 16237 URLs | 3 files read, 255 left unread | 0 with lastmod | 0.3s | problems: none\n```\n\nEach run takes under a second here. Two details matter. None of the URL entries carries a `lastmod` date, so you can't tell fresh pages from old ones. And `pypi.org` lists 255 more files than this run opened, so a full parse of that site is 258 requests: the index and its 257 files.\n\n## A sitemap can be incomplete or stale\n\nA sitemap lists what the site chooses to list, and nothing checks that against the site. You can check it yourself by reading a sample of the sitemap's own pages and comparing the links on them with the sitemap. First, extract the same-site links from a page:\n\n``` python\n# page_links.py\nfrom html.parser import HTMLParser\nfrom urllib.parse import urldefrag, urljoin, urlsplit\n\nfrom sitemap_urls import fetch\n\nclass Links(HTMLParser):\n    def __init__(self):\n        super().__init__()\n        self.hrefs = []\n\n    def handle_starttag(self, tag, attrs):\n        if tag == \"a\" and dict(attrs).get(\"href\"):\n            self.hrefs.append(dict(attrs)[\"href\"])\n\ndef key(url):\n    parts = urlsplit(urldefrag(url)[0])\n    return f\"{parts.netloc.lower()}{parts.path.rstrip('/')}\"\n\ndef page_links(page_url, get=fetch):\n    \"\"\"Same-site pages a page links to, as absolute URLs without fragments.\"\"\"\n    parser = Links()\n    parser.feed(get(page_url).decode(\"utf-8\", \"replace\"))\n    host = urlsplit(page_url).netloc\n    absolute = (urldefrag(urljoin(page_url, href))[0] for href in parser.hrefs)\n    return sorted({u for u in absolute if urlsplit(u).scheme in (\"http\", \"https\") and urlsplit(u).netloc == host})\n\ndef not_in_sitemap(linked, sitemap_urls):\n    listed = {key(url) for url, _ in sitemap_urls}\n    return sorted(url for url in linked if key(url) not in listed)\n```\n\nThen sample 20 pages spread across the sitemap, collect their links, and note which links the sitemap doesn't list and which listed pages no longer load:\n\n``` python\n# audit.py\nimport time\nfrom collections import Counter\nfrom urllib.parse import urlsplit\n\nimport requests\n\nfrom page_links import not_in_sitemap, page_links\nfrom sitemap_urls import sitemap_urls\n\ndef audit(site, sample=20):\n    \"\"\"Does the sitemap list the pages the site's own pages link to, and do its pages still load?\"\"\"\n    listed = sitemap_urls(site).urls\n    pages = [url for url, _ in listed][::max(1, len(listed) // sample)][:sample]\n    linked, unreadable = set(), []\n    for page in pages:\n        try:\n            linked.update(page_links(page))\n        except requests.RequestException as error:\n            unreadable.append((page, str(error).split(\" for url\")[0]))\n        time.sleep(0.2)\n    return len(pages), len(linked), not_in_sitemap(linked, listed), unreadable\n\ndef section_of(url):\n    return urlsplit(url).path.strip(\"/\").split(\"/\")[0] or \"(home)\"\n\ndef by_section(urls):\n    return Counter(section_of(url) for url in urls)\n```\n\nRun it on the two sites that publish one file:\n\n``` python\nfrom audit import audit, by_section, section_of\n\nfor site in (\"https://yarnpkg.com\", \"https://github.com\"):\n    pages, linked, missing, unreadable = audit(site)\n    print(f\"{site} | {pages} sitemap pages | {linked} distinct same-site links | \"\n          f\"{len(missing)} not in the sitemap | {len(unreadable)} did not load\")\n    sections = by_section(missing)\n    if sections:\n        print(\"   not in the sitemap, by section:\", \", \".join(f\"{name} {count}\" for name, count in sections.most_common(5)))\n        for name, _ in sections.most_common()[5:8]:\n            print(\"   example:\", next(url for url in missing if section_of(url) == name))\n    for url, reason in unreadable:\n        print(\"   did not load:\", url, \"|\", reason)\n```\n\nOutput:\n\n```\nhttps://yarnpkg.com | 20 sitemap pages | 265 distinct same-site links | 0 not in the sitemap | 0 did not load\nhttps://github.com | 20 sitemap pages | 265 distinct same-site links | 122 not in the sitemap | 1 did not load\n   not in the sitemap, by section: organizations 20, signup 19, login 18, account 6, join 6\n   example: https://github.com/solutions/ci-cd/\n   example: https://github.com/resources/articles/devops/what-is-devops\n   example: https://github.com/AgwambaFavour/CheckMe\n   did not load: https://github.com/customer-stories/synergy | 404 Client Error: Not Found\n```\n\nOn `yarnpkg.com` the sitemap and the links agree, so reading the sitemap is all you need for the URL list. On `github.com` the sitemap is the marketing sitemap that robots.txt announces, and it lists 376 pages of a site that has far more. Most of the 122 links it leaves out are account flows (organizations, sign-up, login), which a marketing sitemap omits on purpose. The rest are content pages, such as the solutions and resources pages in the examples, and links out to repositories. One page that the sitemap lists answers a 404. \"Not in the sitemap\" is not the same as \"the sitemap is wrong\", but it tells you whether the sitemap covers the pages you want.\n\nThe parser and audit are about 100 lines you would maintain, and they still don't help when a site publishes no sitemap at all. These tests pin the rules that are easiest to get wrong, plus a stable order for the missing links. The files in them are hand-written for testing:\n\n``` python\n# test_sitemaps.py\nfrom page_links import not_in_sitemap\nfrom sitemap_urls import sitemap_urls\n\nNS = 'xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"'\n\ndef urlset(*locs, ns=NS):\n    return f'<urlset {ns}>' + \"\".join(f\"<url><loc>{u}</loc></url>\" for u in locs) + \"</urlset>\"\n\ndef index(*locs):\n    return (f'<sitemapindex {NS}>' + \"\".join(f\"<sitemap><loc>{u}</loc></sitemap>\" for u in locs) + \"</sitemapindex>\").encode()\n\ndef fake(files):\n    \"\"\"Hand-written files for testing the parser. Not data from a real site.\"\"\"\n    def get(url):\n        if url not in files:\n            raise OSError(f\"404 {url}\")\n        return files[url]\n    return get\n\ndef test_an_index_is_followed_and_max_children_leaves_the_rest_unread():\n    files = {\"https://a.test/robots.txt\": b\"Sitemap: https://a.test/index.xml\",\n             \"https://a.test/index.xml\": index(\"https://a.test/1.xml\", \"https://a.test/2.xml\", \"https://a.test/3.xml\"),\n             \"https://a.test/1.xml\": urlset(\"https://a.test/x\").encode(),\n             \"https://a.test/2.xml\": urlset(\"https://a.test/y\").encode()}\n    found = sitemap_urls(\"https://a.test\", max_children=2, get=fake(files))\n    assert [u for u, _ in found.urls] == [\"https://a.test/x\", \"https://a.test/y\"]\n    assert found.read == 3 and found.skipped == 1 and found.problems == []\n\ndef test_a_missing_guess_is_not_a_problem_but_a_missing_announced_file_is():\n    guessed = sitemap_urls(\"https://a.test\", get=fake({\"https://a.test/sitemap.xml\": urlset(\"https://a.test/x\").encode()}))\n    assert guessed.problems == []\n    announced = sitemap_urls(\"https://b.test\", get=fake({\"https://b.test/robots.txt\": b\"Sitemap: https://b.test/gone.xml\"}))\n    assert announced.urls == [] and \"gone.xml\" in announced.problems[0]\n\ndef test_the_missing_links_come_back_in_a_stable_order():\n    linked = {\"https://a.test/z\", \"https://a.test/b\", \"https://a.test/m\"}\n    assert not_in_sitemap(linked, []) == [\"https://a.test/b\", \"https://a.test/m\", \"https://a.test/z\"]\n```\n\nOutput:\n\n``` bash\n$ pytest -q\n...                                                                      [100%]\n3 passed in 0.06s\n```\n\n## Map the site\n\n[Map](https://docs.spidra.io/map) answers in one request. It reads the sitemap and the links on the start page and on a limited number of further pages, and it returns URLs with the link text each one was found under. It returns URLs, not page content. `sitemap` takes `\"include\"` (the default, sitemap and links), `\"only\"` or `\"skip\"`, and `search` narrows the list to a topic. Install the SDK with `pip install spidra` (Python 3.9 or later) and put your key in `SPIDRA_API_KEY`. This maps `books.toscrape.com`, a site with no sitemap, and asks for five URLs back:\n\n``` python\nimport os\n\nfrom spidra import Spidra\n\nclient = Spidra(api_key=os.environ[\"SPIDRA_API_KEY\"])\nsite = client.map(\"https://books.toscrape.com/\", limit=5)\nprint(site.total, \"URLs |\", site.sources, \"| credits:\", site.credits_used, \"|\", site.duration_ms, \"ms\")\nfor link in site.links:\n    print(link.url, \"|\", link.title)\n```\n\nOutput:\n\n```\n124 URLs | {'sitemap': 0, 'pages': 124} | credits: 1 | 1765 ms\nhttps://books.toscrape.com/ | Books to Scrape\nhttps://books.toscrape.com/catalogue/category/books_1/index.html | Books\nhttps://books.toscrape.com/catalogue/category/books/travel_2/index.html | Travel\nhttps://books.toscrape.com/catalogue/category/books/mystery_3/index.html | Mystery\nhttps://books.toscrape.com/catalogue/category/books/historical-fiction_4/index.html | Historical Fiction\n```\n\n`total` counts every URL Map found, and `limit` only caps how many come back. The `sources` split shows that all 124 came from page links and none from a sitemap. The five URLs are the home page and category pages, which are the site's structure, and the book pages sit behind those listings. A map costs 1 credit whatever the number of URLs. Asking for the sitemap alone shows what happens when there isn't one:\n\n```\nonly = client.map(\"https://books.toscrape.com/\", sitemap=\"only\")\nprint(only.total, \"URLs | credits:\", only.credits_used, \"|\", only.message)\n```\n\nOutput:\n\n```\n0 URLs | credits: 0 | This site doesn't publish a sitemap we could read. Try sitemap: \"include\" to read its links instead.\n```\n\nNothing found costs nothing. Map can only list what the sitemap or the site's links expose, so a page with no link to it and no sitemap entry won't appear. Map is also not a walk of every listing page, so a deep catalogue needs a different tool.\n\n## Crawl for the pages themselves\n\n[Crawl](https://docs.spidra.io/crawl) starts at one URL, follows links toward the pages you describe in plain language, and returns those pages with their content. Pages it reads only to find others are navigation pages: they aren't returned and aren't charged. Here the instruction is \"Individual book pages\" and the crawl stops after two. A crawl runs as a job, so the code starts it and polls:\n\n``` python\nimport time\nfrom datetime import datetime\n\nfrom spidra import CrawlParams\n\nqueued = client.start_crawl(CrawlParams(base_url=\"https://books.toscrape.com\", crawl_instruction=\"Individual book pages\", max_pages=2))\nwhile (job := client.get_crawl(queued.job_id)).status in (\"waiting\", \"active\", \"running\", \"delayed\"):\n    time.sleep(5)\nif job.status != \"completed\":\n    raise RuntimeError(f\"crawl {job.status}: {getattr(job, 'error', None)}\")\n\nfor page in job.result:\n    print(page.url, \"|\", page.title)\n\ndetails = client.get_crawl_job_details(queued.job_id)\nreport = client.crawl_report(queued.job_id).report\nstart, end = (datetime.fromisoformat(t.replace(\"Z\", \"+00:00\")) for t in (details.created_at, details.updated_at))\nprint(job.total_pages, \"pages |\", details.credits_used, \"credits |\", int((end - start).total_seconds()), \"s |\",\n      \"navigation pages (free):\", report.navigation_pages, \"| skipped:\", report.skipped_total)\nprint(\"understood as:\", report.understood_as)\n```\n\nOutput:\n\n```\nhttps://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html | A Light in the Attic | Books to Scrape - Sandbox\nhttps://books.toscrape.com/catalogue/tipping-the-velvet_999/index.html | Tipping the Velvet | Books to Scrape - Sandbox\n2 pages | 2.00 credits | 18 s | navigation pages (free): 1 | skipped: 0\nunderstood as: Individual product detail pages for books.\n```\n\nThe crawl understood the instruction as individual book pages, read one navigation page to get there, and returned two books for 2 credits. Where Map returned the site's structure, Crawl returned the pages at the end of it. A few settings keep a crawl on target:\n\n- `crawl_instruction` should name the kind of page you want. \"Individual book pages\" returns books, and \"All pages\" returns category and listing pages too.\n- A crawl stays under the start URL's path. Start at the section you want, or set`crawl_entire_domain=True` and fence it with`include_paths` .\n- `respect_robots` is off by default on both Map and Crawl. Set`respect_robots=True` if your use requires it.\n- The crawl report lists every link it skipped with a reason, such as`not_relevant` or`outside_start_path` , so a missing page is a question you can answer.\n\n## Three sites, three structures\n\nPut the evidence side by side:\n\n**books.toscrape.com**\n **has no sitemap.** Asking Map for the sitemap alone finds nothing. Map listed 124 URLs from page links in 1.8 seconds for 1 credit, and they are the site's structure. Crawl returned the book pages themselves, 2 credits for 2 pages in 18 seconds.\n**yarnpkg.com**\n **has a complete sitemap.** One file gave 407 URLs in 0.7 seconds, and the audit found nothing the sitemap leaves out. Reading the sitemap wins.\n**github.com**\n **has a partial sitemap.** The marketing sitemap lists 376 URLs, 122 links in the sample fall outside it, and one listed page doesn't load.\n\n```\n[NEED: for yarnpkg.com and github.com, the URLs found by client.map(site) and by a bounded crawl, their overlap with the sitemap, what only one method found, time and credits]\n```\n\n## The decision tree\n\nWork down the questions in order:\n\n- **Do you already have the URLs?** Batch scrape them. You don't need any of the three.\n- **Do you only need the URLs, not the page content?** Read the sitemap if the site has one you trust, which is free (check it with the audit above), or ask Map for`sitemap=\"only\"` for 1 credit. If the sitemap is missing, partial or stale, use Map with its defaults, and add`search` to narrow the list to a topic.\n- **Do you need page content, and can you list the pages first?** Map the site, filter the URLs, then batch scrape them. That is predictable and repeatable, and[Map a website and scrape only the pages you need](https://spidra.io/blog/map-website-batch-scrape-selected-pages) shows the flow.\n- **Do you need content from pages you can describe but can't list?** Crawl with an instruction, start in the right section, and fence it with`include_paths` . The[Crawl API guide](https://spidra.io/blog/spidra-crawl-api-guide) covers crawl settings in depth.\n\n## Mistakes to avoid\n\n- **Crawling to get a list of URLs.** Crawl charges per page returned and reads content you may not need. Map lists URLs for 1 credit.\n- **Trusting a sitemap as complete.** The`github.com` sitemap above is a section of a site. Audit it before you rely on it.\n- **Mapping when you need content.** Map returns URLs and link text. It doesn't read the pages.\n- **Describing the pages loosely.** An instruction such as \"All pages\" returns category and listing pages along with the pages you wanted.\n\n## What this comparison doesn't cover\n\n- Map and Crawl depend on how a site links its pages, so run Map on your own site before you plan a crawl.\n- The audit samples 20 pages. It shows whether a sitemap covers the links near its own pages, not whether it covers the whole site.\n- Results change as sites change, and a sitemap that is complete today can be stale next month.\n- Check a site's terms and robots rules before you crawl it.\n\n## Conclusion\n\nThe cheapest tool that answers your question is the right one. A sitemap you trust is free, Map covers a site with no usable sitemap for 1 credit, and Crawl is for the pages themselves. Spidra gives you all three behind one account, so you pick by the job and not by what is available:\n\n- **Map costs 1 credit whatever the number of URLs.** A site with no sitemap costs the same to map as a site with a huge one, and a map that finds nothing is free.\n- **Crawl returns only the pages you describe.** Pages it reads to find them are free, and a report explains every link it skipped.\n- **Failures are free.** Failed pages and failed crawls aren't charged.\n- **Fetching is handled.** Real browsers, proxies and CAPTCHA solving are included, so you spend your time on the question and not on getting the page.\n- **The next step is in the same account.** Batch scrape the URLs you pick with a schema, search for sites when you don't have one, or parse documents you find, all on one credit balance.\n\nEvery plan has every feature, and the dashboard's Code button writes the request for whatever you set up. [Create a free account](https://app.spidra.io/), set `SPIDRA_API_KEY`, and map a site you care about before you decide whether it needs a crawl.", "url": "https://wpnews.pro/news/sitemap-xml-vs-website-mapping-vs-crawling", "canonical_source": "https://spidra.io/blog/sitemap-vs-map-vs-crawling", "published_at": "2026-11-25 00:00:00+00:00", "updated_at": "2026-11-26 00:42:58.963840+00:00", "lang": "en", "topics": ["ai-crawlers"], "entities": ["Spidra"], "also_reported_by": [], "takeaway": "Read Sitemap lines from robots.txt and fall back to /sitemap.xml and /sitemap_index.xml, following sitemap index files and decompressing gzip, to collect every <loc> for free at one request per file instead of paying 1 credit per page to crawl.", "recommendation": {"advice": "Use the sitemap parser to enumerate URLs for free before crawling, cap child sitemaps with max_children, and record failed files without aborting the run.", "playbook": "rag-retrieval", "playbook_url": "https://wpnews.pro/playbooks/rag-retrieval"}, "alternates": {"html": "https://wpnews.pro/news/sitemap-xml-vs-website-mapping-vs-crawling", "markdown": "https://wpnews.pro/news/sitemap-xml-vs-website-mapping-vs-crawling.md", "text": "https://wpnews.pro/news/sitemap-xml-vs-website-mapping-vs-crawling.txt", "jsonld": "https://wpnews.pro/news/sitemap-xml-vs-website-mapping-vs-crawling.jsonld"}}