Audit Website CTAs with a Python Inventory Script

Zusammenfassung

Pixel shares a Python script for extracting button and link labels across multiple website pages and grouping them by destination. The announcement explains how to spot inconsistent wording, confusing targets, and vague CTAs, while noting that the script reads server-rendered HTML only.

DEV Community

Build a Call-to-Action Inventory: Extract Every Button and Link Label Across Your Site With Python

A homepage might say "Book a free call", the pricing page "Get started", the footer "Contact sales" and the blog "Talk to us". Four labels for one action. A free brand audit of your page copy will flag this on one page; this script shows it across the whole site. import re, urllib.request
from html.parser import HTMLParser
from collections import Counter, defaultdict

class CTA(HTMLParser):
def init(self):
super().init(); self.stack = []; self.found = []
def handle_starttag(self, tag, attrs):
a = dict(attrs)
if tag == "button" or (tag == "a" and re.search(r"btn|button|cta", a.get("class", ""))):
self.stack.append([tag, a.get("href", ""), ""])
def handle_data(self, d):
if self.stack: self.stack[-1][2] += d
def handle_endtag(self, tag):
if self.stack and self.stack[-1][0] == tag:
t, href, text = self.stack.pop()
text = " ".join(text.split())
if text: self.found.append((text, href))

def ctas(url):
html = urllib.request.urlopen(urllib.request.Request(url, headers={"User-Agent": "cta-inventory"})).read().decode("utf-8", "ignore")
p = CTA(); p.feed(html); return p.found

pages = ["https://example.com/", "https://example.com/services", "https://example.com/about"]
by_target = defaultdict(Counter)
for u in pages:
for text, href in ctas(u):
by_target[href or "(no href)"][text] += 1
for href, labels in by_target.items():
flag = " <- several labels" if len(labels) > 1 else ""
print(href, dict(labels), flag)
Reading the output One target, several labels: pick one label and use it everywhere. One label, several targets: "Get started" that sometimes opens a form and sometimes a pricing page confuses people. Vague labels: "Learn more" and "Click here" tell the user nothing. Limits This reads server HTML only. If your buttons render with JavaScript, extract the rendered DOM first. Class-name matching is a heuristic; adjust the regex to your theme. Combine the inventory with a tone check per page. The blunt single-page roast in the War Room gives a quick blunt read of a single page if you want a second opinion.
Audit Website CTAs with a Python Inventory Script
Powered by Readybot.io

Das Neueste von Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …