Detect Google AdSense with Python: From Fast HTTP Scraping to Playwright Stealth
Detecting whether a website is running Google AdSense is a common task for digital marketers, SEO researchers, and competitive intelligence analysts. AdSense works by injecting a specific JavaScript library into the page, accompanied by a unique Publisher ID (formatted as pub-xxxxxxxxxxxxxxxx) and ad container tags (<ins class="adsbygoogle">).
Depending on whether the target website uses static HTML, lazy loading, or Web Application Firewalls (Cloudflare/Akamai), you need different strategies ranging from lightweight HTTP requests to full browser automation with Playwright.
To verify Google AdSense presence, inspect four signals:
- Script Tags:
adsbygoogle.jsorpagead2.googlesyndication.com - Ad Containers:
<ins class="adsbygoogle">DOM elements - Publisher ID: Regex
pub-\d{16}in page source - ads.txt: Record containing
google.com, pub-XXXXXXXXXXXXXXXX, DIRECTat/ads.txt
