Deduplicate URLs without merging different pages
Keep meaningful market, variant and browser context in your collection identity.

Two URLs can lead to the same useful observation, and one URL can produce several different observations. A deduplication rule that ignores that distinction may save requests while silently removing the data your job was meant to collect. Define the identity of the work before deciding which addresses to collapse.
Separate request identity from record identity
A transport-level key helps avoid fetching the same resource repeatedly within a run. A collection key identifies the observation you intend to retain. For a product page, that key may need the market, selected variant or rendering context in addition to the URL.
Keep the requested address and final response address in the collection metadata when they are relevant. A redirect is evidence of what happened to that request, not a universal instruction to merge every future observation under the destination. A store can redirect differently when the market or session changes.
Normalize only what you can justify
Scheme and host names are case-insensitive under generic URI syntax. That does not give you permission to lowercase a whole URL. Path and query components can carry case-sensitive information, and changing them may change the selected resource.
Do not assume that sorting query parameters, removing repeated parameters or dropping an empty value is harmless. Their meaning belongs to the application. A parameter that looks like tracking in one application can select a product, search state or signed resource in another.
Encoding also matters. Decoding a reserved character can alter how a URL is interpreted. Keep an unmodified copy of the discovered address, and make every normalization step traceable so a rejected or merged item can be investigated.
Treat fragments according to the collector
A fragment is normally separated from the URI used for the server request. A browser application can still use that fragment to select a route or state after the page loads. Removing it may be reasonable for a known static-document fetch and wrong for a browser-rendered collection task.
The helper below preserves the full input URL by default and includes an explicit market key. Fragment removal is an opt-in decision for a workload where it has been verified as appropriate.
from urllib.parse import urldefrag
def collection_key(url, market, drop_fragment=False):
if drop_fragment:
url, _ = urldefrag(url)
return (market, url)
This is an illustrative identity helper, not a general URL canonicalizer or a security validator. It leaves query order, encoding and case untouched. Use a consistent market identifier in your own application; passing inconsistent labels will create inconsistent keys.
Keep meaningful variants separate
For a retail collector, test whether size and color selections change the record you need. If they do, preserve that selection in the collection identity even when the browser address stays the same. If the task intentionally collects only one representative page per product, document that narrower coverage.
Likewise, matching URLs from different markets should not automatically collapse into one price observation. Keep currency, tax presentation and intended location available for validation. A deduplication decision should follow the definition of the dataset rather than whichever string happens to be easiest to compare.
Separate exact replay detection from a new observation of a changing page. Fetching an item tomorrow may be valid history, even if its URL is unchanged. Scope a visited set to the intended run or observation window instead of letting it suppress future collection indefinitely.
Test merges as well as duplicates
Create fixture pairs that should merge and pairs that must remain separate. Include the same page with two irrelevant fragments, two meaningful browser routes, repeated query keys, a case-sensitive path and an identical address collected for different markets.
Record which rule caused a merge and retain enough metadata to audit it. Sample the merged group during a pilot: a lower request count is not proof that coverage stayed correct. If your rules discard a meaningful variant, the export can look tidy while representing an incomplete dataset.
Coordinate identity rules with pagination reconciliation and output replay handling. Resolve discovered links and apply destination controls separately; deduplication does not make an untrusted URL safe to fetch.
