Playground Sign in Start free

How to Build a Website Content Inventory Before a Migration

Download runnable code Sign in to prefill your key
Content inventory to CSV Download
Content inventory template Download CSV
1

What a content inventory is

A website content inventory is a spreadsheet with one row per URL and the facts you need before a migration: status code, title, canonical URL, depth and how many pages link to it. One crawl of the site as plain HTML builds it. Our crawl of ujeebu.com recorded 101 URLs with "max_pages": 100, for 100 credits, and the same script lists the broken links and drafts the redirect map.

FileOne row perUse it to
inventory.csvURL foundAudit the whole site: state, status, title, canonical, depth, links out and in, then your action and notes.
broken-links.csvURL answering 404 or 410Fix the links to it, or give it a redirect target.
redirects.csvPage readStart the redirect map: old URL, new URL, and a note for duplicates.
Know the cost before you crawl

A free quote gives the most a crawl can cost before it starts, and max_credits is a hard cap: the job stops before a page that would pass it. Plain HTML costs 1 credit a page.

To compare the crawl with the sitemap and find orphan pages, see How to find all pages on a website. The use case Content inventory for migrations covers the whole migration.

2

The content inventory template

The inventory is a CSV file with these columns. The script fills every one of them except action and notes, which are the audit: your decision for each URL. Download the empty template from the box at the top of the page, or let the script write it filled in.

content-inventory-template.csv
url,state,http_status,error_class,title,canonical_url,duplicate_of,depth,links_out,links_in,action,notes
ColumnWhat goes in it
state, http_status, error_classWhether the page was read, the status code the site answered, and why a page has no content (not_found, blocked, duplicate...).
title, canonical_url, duplicate_ofThe page title, the canonical URL it declares, and the page of the crawl it repeats.
depth, links_out, links_inClicks from the start URL, links on the page, and crawled pages linking to it.
actionYours: keep, update, merge, redirect or remove.
notesYours: owner, new URL, anything the migration team needs.
3

Crawl as HTML without JavaScript

For an inventory you need the links and the head of each page, not clean text. Plain HTML without JavaScript is the cheapest page (1 credit), and its link list comes from every a[href] on the page. If the site only renders with JavaScript, set page.js to true (5 credits a page).

CRAWL = {
    "urls": ["https://ujeebu.com/"],
    "scope": {"max_depth": 2, "max_pages": 100},
    "format": "html",
    "page": {"js": False},      # plain HTML: the cheapest page
    "max_credits": 150,
    "concurrency": 3,
}
job = api("POST", "/crawl", json=CRAWL)
job = wait(job["job_id"])
pages = list(page_records(job["job_id"]))
Exclude filter and tag URLs up front

Listing pages often link to the same list filtered or sorted (?tag=, ?sort=), each with a canonical link back to the list. A duplicate is only known after the page is read, so each one is billed like any page read: a link crawl of the ujeebu.com blog read 113 pages, 64 of them tag and author views such as /blog?tag=geo. Add them to exclude before you start, for example "/blog?tag=*".

Without include patterns the crawl stays on the start URL's host (www. counts as the same host) and follows every link it finds, breadth first. max_depth counts link hops from the start URL. For a large site, run one job per section with include patterns, under its own max_credits; the limits per job are on the Crawl API docs.

4

What a page record holds

Reading the records without content=true is enough: each one already has the fields of the inventory. Here is a page that declares another URL as its canonical:

Two page records (trimmed)
{
  "seq": 58,
  "url": "https://ujeebu.com/case-study/cline",
  "state": "done",
  "http_status": 200,
  "title": "Scaling to 200 Requests/Second - Cline Case Study | Ujeebu",
  "canonical_url": "https://ujeebu.com/solutions/scaling-200-requests-per-second",
  "depth": 1,
  "discovered_from": "https://ujeebu.com/",
  "links": ["https://ujeebu.com/", "https://ujeebu.com/scrape", "..."],
  "links_total": 93,
  "bytes": 111200,
  "sha256": "4112a5e52f456cfa0ecc17ac7c0b9f0983e3b4d4b2cb3c680908812a2926261d"
}

{
  "seq": 64,
  "url": "https://ujeebu.com/solutions/scaling-200-requests-per-second",
  "state": "skipped",
  "error_class": "duplicate",
  "duplicate_of": "https://ujeebu.com/case-study/cline",
  "error": "same document as https://ujeebu.com/case-study/cline",
  "depth": 1
}
FieldMeaning
state, http_statusdone, failed or skipped, and the status code the site answered.
error_classWhy a page has no content: not_found, blocked, timeout, robots, duplicate, busy, stopped or error.
canonical_urlThe canonical URL the page declares, when it differs from the URL.
duplicate_ofThe page of the job this one is the same document as, found through its canonical link.
depth, discovered_fromLink hops from a start URL, and the page where the URL was first found.
links, links_totalThe page's links (up to 300) and how many it has in all.
5

Write inventory.csv

Links out come with each record. Links in are the other way round: for every URL, count the crawled pages whose links contain it. A page with many links in deserves a careful redirect; a page with none may be an orphan.

linked_from = collections.defaultdict(set)
for page in pages:
    for link in page.get("links") or []:
        linked_from[link.split("#")[0]].add(page["url"])

with open("inventory.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["url", "state", "http_status", "error_class", "title", "canonical_url", "duplicate_of",
                  "depth", "links_out", "links_in", "action", "notes"])
    for p in pages:
        out.writerow([p["url"], p["state"], p.get("http_status", ""), p.get("error_class") or "",
                      p.get("title", ""), p.get("canonical_url", ""), p.get("duplicate_of", ""),
                      p["depth"], p.get("links_total", 0), len(linked_from[p["url"]]), "", ""])
inventory.csv (first rows)
url,state,http_status,error_class,title,canonical_url,duplicate_of,depth,links_out,links_in,action,notes
https://ujeebu.com/,done,200,,Web Scraper API - Automate Data Scraping & Extraction | Ujeebu,,,0,95,99,,
https://ujeebu.com/scrape,done,200,,"Web Scraping API: JavaScript Rendering, Rotating Proxies, Pay Only for Success | Ujeebu",,,1,123,89,,
https://ujeebu.com/recipes,done,200,,Recipes: Ready-Made Scrapers for Popular Sites | Ujeebu,,,1,529,89,,
https://ujeebu.com/case-study/cline,done,200,,Scaling to 200 Requests/Second - Cline Case Study | Ujeebu,https://ujeebu.com/solutions/scaling-200-requests-per-second,,1,93,1,,
https://ujeebu.com/solutions/scaling-200-requests-per-second,skipped,,duplicate,,,https://ujeebu.com/case-study/cline,1,0,87,,
...

The last two columns stay empty for your audit. The Python and Node.js scripts write the same three files: on the same job, all three were identical, line for line.

6

List the broken links

A URL that answers 404 or 410 is recorded as failed with error_class not_found. The pages that link to it come from the same links-in map, so each broken URL in the file lists where to fix it.

broken = [p for p in pages if p.get("error_class") == "not_found"]
with open("broken-links.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["broken_url", "http_status", "linked_from"])
    for p in broken:
        out.writerow([p["url"], p.get("http_status", ""), " ".join(sorted(linked_from[p["url"]]))])

The first 100 pages of ujeebu.com had no broken links. This is how a missing page reads, from a one-page job we started on a URL that does not exist:

A not_found page record (trimmed)
{
  "seq": 1,
  "url": "https://books.toscrape.com/catalogue/the-page-that-moved_999/index.html",
  "state": "failed",
  "http_status": 404,
  "error_class": "not_found",
  "error": "Invalid status code from URL: 404",
  "depth": 0
}
Your own pages only

The crawl fetches pages on the allowed hosts. Links to other sites are listed in each page's links but not visited, so this list covers the URLs of your own site.

7

Draft the redirect map

Each page needs a URL on the new site. Two rules give a first draft you can then review:

  • One document, one target. A page that declares another URL as canonical, or that the job found to be the same document as another page, redirects to the URL that stays: the canonical.
  • Path rules. Paths keep their shape on the new site unless a rule in MOVES moves a whole section, for example /blog/ to /resources/blog/.
NEW_SITE = "https://new.example.com"   # where the site is moving
MOVES = [                              # old path prefix -> new path prefix, first match wins
    ("/blog/", "/resources/blog/"),
    ("/docs/", "/developers/docs/"),
]


def keeper(page):
    """The URL that stays for this page's document: the canonical URL, else the page itself."""
    if page.get("duplicate_of") in by_url:
        page = by_url[page["duplicate_of"]]
    return page.get("canonical_url") or page["url"]


with open("redirects.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["old_url", "new_url", "note"])
    for p in pages:
        if p["state"] == "done" or p.get("error_class") == "duplicate":
            keep = keeper(p)
            out.writerow([p["url"], new_url(keep), f"same document as {keep}" if keep != p["url"] else ""])
redirects.csv (selected rows)
old_url,new_url,note
https://ujeebu.com/,https://new.example.com/,
https://ujeebu.com/docs,https://new.example.com/developers/docs,
https://ujeebu.com/docs/apis/scrape,https://new.example.com/developers/docs/apis/scrape,
https://ujeebu.com/case-study/cline,https://new.example.com/solutions/scaling-200-requests-per-second,same document as https://ujeebu.com/solutions/scaling-200-requests-per-second
https://ujeebu.com/playground?endpoint=scrape,https://new.example.com/playground,same document as https://ujeebu.com/playground
...

Review the draft by hand: merge pages that the new site combines, give a target to the broken URLs that still get visits, and drop query-string variants your server already handles. After the move, run the same script on the new site and compare the two inventories: every old URL should now answer with a redirect to a page that exists.

8

Website migration checklist

The inventory is step one. The full sequence, with the file each step uses:

  1. Crawl the old site and write inventory.csv (this script).
  2. Compare the crawl with the sitemaps to catch orphan pages (find all pages on a website).
  3. Fill action for every URL: keep, update, merge, redirect or remove.
  4. Fix or redirect every URL in broken-links.csv.
  5. Review redirects.csv and load it into the new server's redirect rules.
  6. Launch, then crawl the new site with the same script and compare the two inventories: every old URL should redirect to a page that answers 200.
9

The complete script

Set CRAWL["urls"], NEW_SITE and MOVES for your site, then run it. It prints the job's progress, then a summary.

#!/usr/bin/env python3
"""Build a website content inventory before a migration, with the Ujeebu Crawl API.

Crawls the site as HTML without JavaScript (the cheapest format), then writes:
  inventory.csv      the content inventory: one row per URL with status, title, canonical, depth,
                     links in and out, plus empty action and notes columns for the audit
  broken-links.csv   URLs that answer 404 or 410, with the pages that link to them
  redirects.csv      a first redirect map: each page and its URL on the new site

    pip install requests
    UJEEBU_API_KEY=your-key python3 site_inventory.py
"""
import collections
import csv
import os
import time
from urllib.parse import urlparse

import requests

API_KEY = os.environ.get("UJEEBU_API_KEY", "YOUR_API_KEY")
API = "https://api.ujeebu.com"

CRAWL = {
    "urls": ["https://ujeebu.com/"],
    "scope": {"max_depth": 2, "max_pages": 100},
    "format": "html",
    "page": {"js": False},      # plain HTML: the cheapest page
    "max_credits": 150,
    "concurrency": 3,
}
NEW_SITE = "https://new.example.com"   # where the site is moving
MOVES = [                              # old path prefix -> new path prefix, first match wins
    ("/blog/", "/resources/blog/"),
    ("/docs/", "/developers/docs/"),
]

http = requests.Session()
http.headers["ApiKey"] = API_KEY


def api(method, path, **kwargs):
    """Call the Crawl API. A GET is tried again after a network error: polling runs for minutes."""
    for attempt in range(1, 4):
        try:
            response = http.request(method, API + path, timeout=60, **kwargs)
            break
        except requests.ConnectionError:
            if method != "GET" or attempt == 3:
                raise
            time.sleep(5 * attempt)
    if response.status_code >= 400:
        raise SystemExit(f"{method} {path}: {response.status_code} {response.text}")
    return response.json()


def wait(job_id):
    while True:
        job = api("GET", f"/crawl/{job_id}")
        if job["finished"]:
            return job
        print(f"  {job['status']}: {job['counts']['done']} done, {job['counts']['pending']} pending")
        time.sleep(10)


def page_records(job_id):
    after = 0
    while True:
        batch = api("GET", f"/crawl/{job_id}/pages", params={"after": after, "limit": 50})
        yield from batch["pages"]
        if not batch["has_more"]:
            return
        after = batch["next_after"]


def new_url(url):
    """The page's URL on the new site: same path, unless a MOVES rule applies."""
    path = urlparse(url).path or "/"
    for old, new in MOVES:
        old, new = old.rstrip("/"), new.rstrip("/")
        if path == old or path.startswith(old + "/"):
            return NEW_SITE + new + path[len(old):]
    return NEW_SITE + path


def keeper(page):
    """The URL that stays for this page's document: the canonical URL, else the page itself."""
    if page.get("duplicate_of") in by_url:
        page = by_url[page["duplicate_of"]]
    return page.get("canonical_url") or page["url"]


job = api("POST", "/crawl", json=CRAWL)
print(f"Started {job['job_id']}")
job = wait(job["job_id"])
pages = list(page_records(job["job_id"]))
by_url = {p["url"]: p for p in pages}

# Who links to whom: links are absolute URLs, one list per page (up to 300, links_total says how many).
linked_from = collections.defaultdict(set)
for page in pages:
    for link in page.get("links") or []:
        linked_from[link.split("#")[0]].add(page["url"])

with open("inventory.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["url", "state", "http_status", "error_class", "title", "canonical_url", "duplicate_of",
                  "depth", "links_out", "links_in", "action", "notes"])
    for p in pages:
        out.writerow([p["url"], p["state"], p.get("http_status", ""), p.get("error_class") or "",
                      p.get("title", ""), p.get("canonical_url", ""), p.get("duplicate_of", ""),
                      p["depth"], p.get("links_total", 0), len(linked_from[p["url"]]), "", ""])

broken = [p for p in pages if p.get("error_class") == "not_found"]
with open("broken-links.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["broken_url", "http_status", "linked_from"])
    for p in broken:
        out.writerow([p["url"], p.get("http_status", ""), " ".join(sorted(linked_from[p["url"]]))])

with open("redirects.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["old_url", "new_url", "note"])
    for p in pages:
        if p["state"] == "done" or p.get("error_class") == "duplicate":
            keep = keeper(p)
            out.writerow([p["url"], new_url(keep), f"same document as {keep}" if keep != p["url"] else ""])

states = collections.Counter(p.get("error_class") or p["state"] for p in pages)
print(f"{len(pages)} URLs: {dict(states)}; {job['credits_used']} credits ({job['stop_reason']})")
print(f"{len(broken)} broken URLs")
for p in broken[:10]:
    print(f"  {p['url']} ({p.get('http_status')}), linked from {len(linked_from[p['url']])} pages")
Run it
# Python 3, the script saved as site_inventory.py
pip install requests
UJEEBU_API_KEY=your-key python3 site_inventory.py

# Node.js 18 or later, the script saved as site-inventory.js
UJEEBU_API_KEY=your-key node site-inventory.js
Output (trimmed)
Started c_fb2fd3be-12e7-4003-90ae-fcdac4dae630
  processing: 0 done, 1 pending
  processing: 14 done, 83 pending
  ...
  processing: 98 done, 0 pending
101 URLs: {'done': 98, 'duplicate': 3}; 100 credits (max_pages)
0 broken URLs

The job reads pages first, then builds its archive; finished turns true once the archive is ready, so the last progress lines can repeat for a little while.

Size the site before the migration

The free sizer lists a site's sitemap URLs as a CSV and quotes the crawl before you spend a credit.

?

Frequently Asked Questions

What is a website content inventory?

A list of every URL on a site with the facts you need to decide what to do with each page: status, title, canonical URL, depth and how many pages link to it. A content audit adds a decision per page, such as keep, update, merge, redirect or remove. One crawl gives you the inventory; the template adds the audit columns.

How do I do a website content audit before a migration?

Crawl the old site, export the inventory, mark an action for each URL, list the broken links, and draft the redirect map from the canonical URLs. After the move, crawl the new site with the same script and compare the two inventories.

Is there a content inventory template?

Yes. The CSV template on this page has the columns url, state, http_status, error_class, title, canonical_url, duplicate_of, depth, links_out, links_in, action and notes. The script fills every column except action and notes, which are yours.

How do I find all URLs before a website migration?

Combine a link crawl with the sitemap list: the crawl finds what visitors can reach, the sitemap what you declared to search engines. Find all pages on a website (/tutorials/find-all-pages-of-a-website) shows how to compare the two and spot orphan pages.

Why crawl HTML without JavaScript for an inventory?

It is the cheapest page (1 credit), and its links come from every a[href] on the page. Markdown link lists leave out links without visible text, such as image-only links. If the site only renders with JavaScript, set page.js to true (5 credits a page).

Does the crawl respect robots.txt?

Yes, for the UjeebuBot token, then *. A disallowed page is recorded with error_class "robots", never fetched, and costs nothing. A Crawl-delay is respected up to 30 seconds.