Start by fetching the HTML of each URL, storing it in the pages table, and extracting useful SEO details into page_summary.
This project is a lightweight, fully functional Python + BeautifulSoup webpage auditor that lets you fetch HTML from any set of URLs, store it in an SQLite database, analyze SEO-related tags, and export the results to Excel for reporting.
All scripts are independent, sharing a common configuration file settings.py, so you can change database paths or root folder settings in one place. Users can download the complete ZIP containing the scripts and start running them immediately.
DB_PATH, ROOT_PATH, User-Agent string, and timeout values.pages table. Each run can append new URLs without affecting others.pages table, extracts key SEO tags (title, description, keywords, canonical URL, schema, image alt coverage, etc.), and saves them in page_summary table.query variable for custom reports or deletions.page_summary and exports them to Excel for easy sharing and further analysis.pages table for archival purposes.page_summary.SELECT url FROM page_summary WHERE LENGTH(title) < 50page_summary table, which can be directly shared with your team or clients.title or meta description is missing or too short.canonical tags or og:* social meta tags.Unlike online SEO checkers, this tool lets you audit hundreds of pages offline, retain historical data in a database, and customize your own queries for deeper analysis. It's ideal for webmasters, SEO analysts, and developers who want full control over their audit process.
page_summary.py can be easily extended to capture additional HTML tags, schema types, or even custom string patterns relevant to your project.DB_PATH and ROOT_PATH in settings.py to match your local directory.pip install requests beautifulsoup4 lxml pandas openpyxl 📥 Download ZIP of Python Webpage Auditor V1 📥 Download ZIP of Python Webpage Auditor V2
Choose a method based on where you keep the fetched HTML: SQLite for the original Python project, MySQL for server-side SQL checks, or Excel for reviewing and sharing results.
Practical SEO checks you can run from your SQLite database.
pages (raw HTML) and summaries in page_summary.query line to answer a specific SEO question.pages):SELECT url
FROM pages
WHERE html NOT LIKE '%<title%'
OR LENGTH(substr(html, instr(html, '<title>')+7,
instr(html, '</title>')-instr(html, '<title>')-7)) < 20;
page_summary):SELECT url, canonical_url
FROM page_summary
WHERE canonical_url IS NOT NULL
AND canonical_url != url;
rel="canonical" to the preferred, crawlable URL.pages):SELECT url
FROM pages
WHERE html NOT LIKE '%G-%' -- quick GA4 id presence check
OR html NOT LIKE '%gtag(';
pages):SELECT url, LENGTH(html) AS bytes
FROM pages
ORDER BY LENGTH(html)
LIMIT 20;
pages):SELECT url
FROM pages
WHERE html NOT LIKE '%<meta name="description"%';
page_summary):SELECT title, COUNT(*) AS cnt, GROUP_CONCAT(url, ' | ') AS urls
FROM page_summary
WHERE title IS NOT NULL AND title != ''
GROUP BY title
HAVING COUNT(*) > 1;
page_summary):-- Empty H1s
SELECT url
FROM page_summary
WHERE h1 IS NULL OR TRIM(h1) = '';
-- Duplicate H1s
SELECT h1, COUNT(*) AS cnt, GROUP_CONCAT(url, ' | ') AS urls
FROM page_summary
WHERE h1 IS NOT NULL AND TRIM(h1) != ''
GROUP BY h1
HAVING COUNT(*) > 1;
page_summary):SELECT url, broken_link
FROM page_summary
WHERE broken_link IS NOT NULL;
query in your existing analysis script for any check above.page_summary to Excel/CSV for progress tracking.After fetching the pages, run these MySQL 8.0 queries against the pages table to find URLs requiring review. The source data uses the columns id, url, and html_content. These MySQL examples are separate from the SQLite analysis queries above.
Find pages where the HTML title is missing or contains fewer than 20 characters. This is a review threshold, not a Google requirement.
SELECT id, url
FROM pages
WHERE html_content IS NULL
OR NOT REGEXP_LIKE(html_content, '<title[[:space:]>]', 'i')
OR CHAR_LENGTH(TRIM(COALESCE(
REGEXP_REPLACE(
REGEXP_SUBSTR(html_content, '<title[^>]*>[^<]*</title[[:space:]]*>', 1, 1, 'i'),
'</?title[^>]*>', '', 1, 0, 'i'
), ''
))) < 20;
Locate missing description tags or descriptions shorter than 50 characters. The check assumes a standard quoted content attribute and handles either common attribute order.
WITH descriptions AS (
SELECT id, url,
REGEXP_SUBSTR(
html_content,
'<meta[[:space:]]+(?=[^>]*name[[:space:]]*=[[:space:]]*["'']description["''])[^>]*>',
1, 1, 'i'
) AS meta_tag
FROM pages
), extracted AS (
SELECT id, url, meta_tag,
REGEXP_REPLACE(
REGEXP_SUBSTR(meta_tag, 'content[[:space:]]*=[[:space:]]*["''][^"'']*["'']', 1, 1, 'i'),
'^content[[:space:]]*=[[:space:]]*["'']|["'']$', '', 1, 0, 'i'
) AS description_text
FROM descriptions
)
SELECT id, url, description_text
FROM extracted
WHERE meta_tag IS NULL
OR description_text IS NULL
OR CHAR_LENGTH(TRIM(description_text)) < 50;
Count pages containing the expected GA4 measurement-ID prefix. Replace G-DXKV with the full measurement ID when available.
SELECT
SUM(CASE WHEN html_content LIKE '%G-DXKV%' THEN 1 ELSE 0 END) AS ga4_present,
SUM(CASE WHEN html_content NOT LIKE '%G-DXKV%'
OR html_content IS NULL THEN 1 ELSE 0 END) AS ga4_missing
FROM pages;
Return the individual URLs requiring a tracking-code check.
SELECT id, url
FROM pages
WHERE html_content NOT LIKE '%G-DXKV%'
OR html_content IS NULL;
Identify fetched pages with fewer than 20,000 bytes of HTML. This flags pages for manual review; HTML size is not the same as visible content length.
SELECT id, url, LENGTH(html_content) AS html_length
FROM pages
WHERE (LENGTH(html_content) < 20000
OR html_content IS NULL)
AND url LIKE '%/javascript_tutorial/%'
ORDER BY html_length;
Find pages containing at least one image tag without an alt attribute, even if other images on the same page have alt text.
SELECT id, url
FROM pages
WHERE REGEXP_LIKE(
html_content,
'<img[[:space:]]+(?:(?![[:space:]]alt[[:space:]]*=)[^>])*>',
'i'
);
Locate pages without a viewport meta tag so they can be checked on mobile devices.
SELECT id, url
FROM pages
WHERE html_content IS NULL
OR NOT REGEXP_LIKE(
html_content,
'<meta[[:space:]]+[^>]*name[[:space:]]*=[[:space:]]*["'']viewport["'']',
'i'
);
Search for pages having unwanted strings .
SELECT id, url
FROM pages
WHERE html_content IS NOT NULL
AND REGEXP_LIKE(
html_content,
'YOUR_WORD',
'i'
);
List pages without a link element declaring rel="canonical". A canonical elsewhere in the document is not counted.
SELECT id, url
FROM pages
WHERE html_content IS NULL
OR NOT REGEXP_LIKE(
html_content,
'<link[[:space:]]+(?=[^>]*rel[[:space:]]*=[[:space:]]*["'']canonical["''])[^>]*>',
'i'
);
Compare the last directory and filename of the fetched URL against the canonical URL. Only URLs with a detected mismatch are returned.
WITH canonical_tags AS (
SELECT id, url,
REGEXP_SUBSTR(
html_content,
'<link[[:space:]]+(?=[^>]*rel[[:space:]]*=[[:space:]]*["'']canonical["''])[^>]*>',
1, 1, 'i'
) AS canonical_tag
FROM pages
), canonical_urls AS (
SELECT id, url,
REGEXP_REPLACE(
REGEXP_SUBSTR(
canonical_tag,
'href[[:space:]]*=[[:space:]]*["''][^"'']+["'']',
1, 1, 'i'
),
'^href[[:space:]]*=[[:space:]]*["'']|["'']$', ''
) AS canonical_url
FROM canonical_tags
), normalized AS (
SELECT id, url, canonical_url,
SUBSTRING_INDEX(SUBSTRING_INDEX(url, '?', 1), '#', 1) AS source_path,
SUBSTRING_INDEX(SUBSTRING_INDEX(canonical_url, '?', 1), '#', 1) AS target_path
FROM canonical_urls
), parts AS (
SELECT id, url, canonical_url,
SUBSTRING_INDEX(SUBSTRING_INDEX(source_path, '/', -2), '/', 1) AS dir1,
SUBSTRING_INDEX(source_path, '/', -1) AS file1,
SUBSTRING_INDEX(SUBSTRING_INDEX(target_path, '/', -2), '/', 1) AS dir2,
SUBSTRING_INDEX(target_path, '/', -1) AS file2
FROM normalized
)
SELECT id, url, canonical_url, dir1, file1, dir2, file2,
CASE
WHEN BINARY dir1 <> BINARY dir2 AND BINARY file1 <> BINARY file2
THEN 'Directory and filename mismatch'
WHEN BINARY dir1 <> BINARY dir2 THEN 'Directory mismatch'
WHEN BINARY file1 <> BINARY file2 THEN 'Filename mismatch'
END AS mismatch_type
FROM parts
WHERE canonical_url IS NOT NULL
AND (BINARY dir1 <> BINARY dir2 OR BINARY file1 <> BINARY file2)
ORDER BY id;
| Field | Fetched URL | Canonical URL |
|---|---|---|
| Directory | python (dir1) | python2 (dir2) |
| Filename | ai-gemini.php (file1) | ai-gemini2.php (file2) |
The canonical is extracted only from the <link rel="canonical"> element, not from unrelated footer links such as terms.html. This comparison intentionally ignores the host and scheme and checks only the immediate parent directory and filename. It does not verify the full path, redirect status, or whether the canonical destination is indexable.
Practical limits: Simple regular expressions can miss unusual HTML formatting. The GA4 check matches a string and does not confirm successful tracking. Images with empty alt="" are considered to have an alt attribute; whether that is appropriate depends on whether an image is decorative. Use an HTML parser for a more complete image accessibility audit.
Once the page data has been fetched and summarized, use page_summary_excel.py to export the page_summary table to an Excel workbook. The exported data can be filtered, sorted, and reviewed without editing the SQLite database.
fetch_store.py to save the webpage HTML in pages.page_summary.py to create or refresh the extracted values in page_summary.page_summary_excel.py to write the summary records to Excel.Excel analysis uses the fields already extracted by page_summary.py. New checks on raw HTML may require adding fields to that extraction step before exporting. The original downloadable ZIP and its filenames remain unchanged.
↑ Back to top / Table of contents
Sqlite Beatutifulsoup Simple Webpage Auditor Create XML Sitemap in PythonAuthor & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.