DEV Community

Ujjwal Dubey
Ujjwal Dubey

Posted on

A Rough Reading-Ease Score for Every Page on Your Site: Spot the Pages That Sound Like a Different Company (Python)

A brand voice usually breaks in a measurable way: one page reads like a legal document, another like a text message. A rough reading-ease score per page will not tell you what is wrong, but it shows where to look before you run a free brand audit tool on the pages that stand out.

Script

import re, sys, urllib.request
from html.parser import HTMLParser

class Text(HTMLParser):
    def __init__(self):
        super().__init__(); self.skip = 0; self.out = []
    def handle_starttag(self, tag, a):
        if tag in ("script", "style", "nav", "footer"): self.skip += 1
    def handle_endtag(self, tag):
        if tag in ("script", "style", "nav", "footer") and self.skip: self.skip -= 1
    def handle_data(self, d):
        if not self.skip: self.out.append(d)

def syllables(word):
    groups = re.findall(r"[aeiouy]+", word.lower())
    n = len(groups) - (1 if word.lower().endswith("e") and len(groups) > 1 else 0)
    return max(1, n)

def reading_ease(text):
    sents = max(1, len(re.findall(r"[.!?]+", text)))
    words = re.findall(r"[A-Za-z']+", text)
    if not words: return None
    syl = sum(syllables(w) for w in words)
    return round(206.835 - 1.015 * (len(words) / sents) - 84.6 * (syl / len(words)), 1)

for url in sys.argv[1:]:
    html = urllib.request.urlopen(urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})).read().decode("utf-8", "ignore")
    p = Text(); p.feed(html)
    print(reading_ease(" ".join(p.out)), url)
Enter fullscreen mode Exit fullscreen mode

Run: python ease.py https://example.com/ https://example.com/about https://example.com/services

Reading the output

  • Higher means easier to read. Look for pages far from the rest, not for a "good" number.
  • Legal and policy pages will score low; exclude them.
  • JavaScript-rendered sites may return little text; render first or paste the copy.

Then what

Take the outlier pages and read them aloud. If they sound like another company, rewrite toward the voice of your best page. A tone checker helps confirm the fix.

For stiff sentences, the War Room humanizer for outlier pages offers a quick rewrite suggestion.

Disclosure: I co-founded NxFlowAI, which makes the free War Room tools.

Top comments (0)