Incremental Web Scraping: Track Changes, Avoid Duplicates, and Resume Failed Jobs
incremental-scrapingdatabasesdeduplicationautomationdata-pipelines

Incremental Web Scraping: Track Changes, Avoid Duplicates, and Resume Failed Jobs

sscraper.page Editorial Team
2026-11-30
7 min read

Build reliable incremental web scraping with stable IDs, content hashes, upserts, checkpoints, retries, and change history.

Incremental web scraping lets you collect only new or changed records instead of downloading an entire source on every run. This guide presents a reusable workflow for stable identifiers, content fingerprints, timestamps, database upserts, checkpoints, retry queues, and change history so scheduled jobs use fewer resources and are easier to recover.

Overview

A full scrape is straightforward: request every page, extract every item, and write the results. It becomes inefficient when the source contains thousands of records but only a small portion changes between runs. Incremental scraping addresses this by comparing the current observation with a stored version and acting only when the record is new, changed, or no longer observed.

The workflow has five core decisions:

  1. Identity: How will you recognize the same item across runs?
  2. Change detection: Which fields determine whether an item changed?
  3. Persistence: Where will the current record, timestamps, and fingerprint be stored?
  4. Recovery: How will a failed run resume without duplicating completed work?
  5. History: Do you need only the latest state, or a record of every observed version?

A stable source identifier is usually the best identity key: a product ID, article ID, listing ID, API key, or canonical URL. Avoid using a title alone because titles can change and different records can share similar text. If a source has no explicit identifier, normalize the canonical URL and use it as a provisional key. Keep the original URL as a separate field so you can diagnose redirects or URL changes later.

For background on extraction and pagination, see How to Scrape a Website with Python and Web Scraper Pagination Patterns. Incremental logic works best after extraction has already been made predictable.

Checklist by scenario

Scenario 1: You need only new records

  • Identify a source field that is unique and persistent.
  • Store that identifier with the first-seen timestamp.
  • Use an upsert or a uniqueness constraint to prevent duplicate inserts.
  • Record the run ID that first discovered the item.
  • Do not assume that sorting by publication date is sufficient; late-arriving or backdated records can be missed.

A minimal current-state table might look like this:

CREATE TABLE scraped_items (
  source_key TEXT PRIMARY KEY,
  canonical_url TEXT,
  title TEXT,
  body TEXT,
  content_hash TEXT NOT NULL,
  first_seen_at TIMESTAMP NOT NULL,
  last_seen_at TIMESTAMP NOT NULL,
  last_changed_at TIMESTAMP NOT NULL,
  last_run_id TEXT NOT NULL
);

The primary key makes duplicate discovery visible rather than silently creating multiple copies. The exact data types depend on your database, but the distinction between last_seen_at and last_changed_at is important: an unchanged item can be observed today without having changed today.

Scenario 2: You need changed records

  • Choose the fields that matter to downstream users.
  • Normalize those fields consistently before hashing.
  • Serialize them in a deterministic order.
  • Compute a content fingerprint with a standard cryptographic hash such as SHA-256.
  • Compare the new fingerprint with the stored fingerprint before updating the record.

Do not hash raw HTML unless markup-level changes are meaningful. A template update, whitespace change, tracking attribute, or reordered element can produce a different HTML hash even when the visible content is unchanged. Instead, select fields such as title, price, status, date, and normalized body text. Define explicitly whether missing, empty, and null values should be treated as equivalent.

payload = {
    "title": normalize_text(item["title"]),
    "status": item.get("status") or "",
    "body": normalize_text(item.get("body", "")),
}

canonical = json.dumps(payload, sort_keys=True, separators=(",", ":"))
fingerprint = hashlib.sha256(canonical.encode("utf-8")).hexdigest()

When the fingerprint differs, update the current row and set last_changed_at. When it matches, update only last_seen_at and the run reference.

Scenario 3: You need an audit trail

  • Keep the current-state table for fast reads.
  • Add a history table keyed by source identifier and observation time.
  • Insert a history row only when the selected content changes, unless every observation must be retained.
  • Store the fingerprint and the normalized fields used to create it.
  • Retain the run ID and extraction metadata for investigation.

A history table can use a compound key such as (source_key, content_hash) when repeated identical versions do not need to be stored. If order matters, use an auto-incrementing version or observed timestamp as well. Decide whether the history is a business record, a debugging aid, or both; that decision affects retention and storage requirements.

Scenario 4: You need jobs that survive interruptions

  • Create a run record before requesting pages.
  • Divide work into durable units such as URLs, page numbers, cursors, or item keys.
  • Mark each unit pending, processing, completed, or failed.
  • Commit each successful unit, or use batches small enough to retry safely.
  • Store the cursor, page number, or queue key needed to resume.
  • Retry transient failures with bounded attempts and delayed backoff.

A checkpoint should represent confirmed progress, not merely the last request started. If a process stops after fetching a page but before committing its records, rerunning that page should be safe because the database key and upsert logic make the operation idempotent.

For request-level reliability, review Reliable Web Scraping Requests. For authenticated sources, keep session and token handling separate from change-detection logic, as described in Scraping Authenticated Websites.

What to double-check

Identifier stability: Confirm that the same source item receives the same key after edits, pagination changes, and redirects. If a URL is the fallback key, normalize scheme, hostname, trailing slash, fragments, and known tracking parameters according to the source.

Normalization rules: Apply the same text cleanup on every run. Use the guidance in Clean and Normalize Scraped Data with Python for consistent whitespace, dates, HTML, and CSV handling. Changing normalization rules changes fingerprints, so record the rule version with each run when reproducibility matters.

Deletion handling: An item absent from one run is not necessarily deleted. The page may be incomplete, a request may have failed, or pagination may have changed. Prefer a last_seen_at threshold or a separate inactive status, and mark items missing only after a defined number of complete runs.

Scope of change: Hash only fields that should trigger downstream work. If a volatile field such as crawl time is included, every observation will appear changed. Conversely, excluding a meaningful status or price update will hide a real change.

Run observability: Record start and finish times, pages attempted, records discovered, records inserted, records changed, records unchanged, retries, and failures. Alert on unusual drops or spikes rather than relying only on process exit status.

Extraction tests: Use saved HTML or API fixtures to verify identifiers, pagination, normalization, and hash inputs. The testing patterns in How to Test Web Scrapers help catch selector and template changes before they corrupt an incremental dataset.

Common mistakes

  • Using a row number as an identity. Pagination order can change, causing one record to look like another.
  • Inserting before deduplicating. A unique constraint or deterministic upsert should be the final safeguard.
  • Updating every row on every run. This erases the distinction between observed and changed data and creates unnecessary downstream work.
  • Hashing unstable content. Crawl timestamps, random IDs, advertisements, and layout markup can create false positives.
  • Saving checkpoints only in memory. A process restart then loses its progress and may repeat expensive work.
  • Retrying forever. Put a limit on attempts and send exhausted items to a review queue with the error details.
  • Treating a partial run as complete. Do not apply deletion or completeness rules until the required pages or cursor range have succeeded.
  • Changing selectors without checking identity. A selector redesign can silently produce null keys or duplicate representations. See the Resilient Web Scraper Selectors guide for strategies that reduce this risk.

When to revisit

Review the incremental workflow before a seasonal planning cycle, before increasing collection frequency, and whenever the source changes its URL structure, pagination, authentication flow, markup, or API response shape. Revisit it when storage grows, processing costs rise, downstream consumers report missed updates, or the ratio of changed records suddenly shifts.

Use this practical runbook:

  1. Run a small sample and verify that stable items retain the same key.
  2. Change one known field and confirm that exactly one fingerprint changes.
  3. Repeat the same input and confirm that the second run produces no duplicate and no false change.
  4. Stop the worker after a committed batch and confirm that the next run resumes safely.
  5. Force a failed request and verify bounded retries, error logging, and queue recovery.
  6. Simulate an incomplete crawl and confirm that missing items are not immediately marked deleted.
  7. Compare run metrics with a recent successful baseline before enabling the schedule.

Keep the schema, normalization rules, selector assumptions, and checkpoint semantics documented beside the scraper code. Incremental web scraping is not a single optimization; it is a contract between extraction, storage, and operations. When each part records enough context to explain what happened, you can scrape only new data, deduplicate scraped records, detect meaningful changes, and resume failed scraper jobs without starting over.

Related Topics

#incremental-scraping#databases#deduplication#automation#data-pipelines
s

scraper.page Editorial Team

Developer Workflow Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.