Sub topic 2
Finding Exact Duplicates with Content Hashes
Assume you know basic HTML, HTTP status codes, redirects, crawl exports, and basic pandas grouping. This chapter uses those skills to separate exact duplicates from near duplicates and thin pages.
Hashing exact duplicates
An exact duplicate has the same meaningful body text as another URL. First remove navigation, cookie banners, footers, and other boilerplate. Then normalize whitespace and letter case. A cryptographic hash converts the resulting text into a fixed-length key. Pages with the same key have identical extracted text.
import hashlib
import pandas as pd
df = pd.read_csv("crawl.csv") # url, status, body_text, word_count
df = df[df["status"] == 200].copy()
def content_hash(text):
cleaned = " ".join(str(text).split()).lower()
return hashlib.sha256(cleaned.encode("utf-8")).hexdigest()
df["body_hash"] = df["body_text"].fillna("").map(content_hash)
groups = df.groupby("body_hash")["url"].agg(list)
duplicates = groups[groups.str.len() > 1]
print(duplicates)An empty body can create a large false duplicate group, so inspect zero-word pages separately. Also compare URL normalization before grouping. Protocol, host, trailing-slash, tracking-parameter, and parameter variants can represent one page.
Estimating near duplicates
Near duplicates differ in a few words, such as product color or location. Word shingles are overlapping groups of words. Jaccard similarity divides shared shingles by all shingles. A score near 1 means the pages are very similar.
def shingles(text, k=5):
words = text.lower().split()
if len(words) < k:
return {" ".join(words)} if words else set()
return {" ".join(words[i:i + k]) for i in range(len(words) - k + 1)}
def jaccard(a, b):
return len(a & b) / len(a | b) if a or b else 0.0
a = shingles("red shoes are lightweight for long road runs")
b = shingles("blue shoes are lightweight for long road runs")
print(round(jaccard(a, b), 2))Choose a threshold from sampled results. Do not treat a threshold as a universal SEO rule.
Reading signals and choosing a URL
Use crawl fields and HTML signals together:
| Signal | Meaning |
|---|---|
| Redirect | The URL sends users and crawlers to another URL |
| Canonical | The page suggests a preferred equivalent URL |
| Noindex | The page asks search engines not to index it |
| Robots exclusion | Crawling is restricted, so content may be unavailable for comparison |
Cluster exact and near duplicates, then select the URL with the strongest intent, links, traffic, stable address, and correct canonical target. Redirect obsolete URLs when users should land on the preferred page. Use a canonical when equivalent URLs must remain accessible. Use noindex for pages that should remain available but out of search results. Consolidate or improve pages when they serve overlapping or weak intent.
Exercise
Two URLs have the same body hash, but one redirects to the other. Which URL should normally remain preferred?
Show answer
The redirect target. Confirm that internal links, sitemap entries, and the canonical signal also point to it.