Python Webpage Auditor – Fetch, Store, Analyze & Export

Part 1: Fetching and Storing Webpage Data

Start by fetching the HTML of each URL, storing it in the pages table, and extracting useful SEO details into page_summary.

Web / URLs HTML Sources fetch_store.py Fetch HTML & Store in DB page_summary.py Extract Tags & Data page_analysis_query.py Run Custom SQL Analysis page_summary_excel.py Export to Excel settings.py Shared Config

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.

1. File Overview

  • settings.py – Common configuration file storing DB_PATH, ROOT_PATH, User-Agent string, and timeout values.
  • fetch_store.py – Fetches the HTML of given URLs and stores them in the pages table. Each run can append new URLs without affecting others.
  • page_summary.py – Reads the raw HTML from pages table, extracts key SEO tags (title, description, keywords, canonical URL, schema, image alt coverage, etc.), and saves them in page_summary table.
  • page_analysis_query.py – Lets you run any SQL query to filter, analyze, or clean data in your database. You can quickly modify the query variable for custom reports or deletions.
  • page_summary_excel.py – Reads all records from page_summary and exports them to Excel for easy sharing and further analysis.

2. How It Works

  1. Run fetch_store.py with your list of URLs. This stores the complete HTML in pages table for archival purposes.
  2. Run page_summary.py to extract SEO-critical elements from the HTML and store them in structured columns in page_summary.
  3. Use page_analysis_query.py to apply filters such as:
    SELECT url FROM page_summary WHERE LENGTH(title) < 50
  4. Run page_summary_excel.py to generate an Excel report from the page_summary table, which can be directly shared with your team or clients.

3. Example Use Cases

  • Check if title or meta description is missing or too short.
  • Find pages without GA4 tracking IDs.
  • Identify low image alt-text coverage for accessibility improvements.
  • Locate pages missing canonical tags or og:* social meta tags.
  • Audit schema presence (FAQPage, HowTo, VideoObject).

4. Why This Project is Useful

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.

  • ⚡ Easy switch over to MySQL – Change the connection code and table creation statements to migrate from SQLite to MySQL if your data grows larger.
  • 🛠 Expandable checks – page_summary.py can be easily extended to capture additional HTML tags, schema types, or even custom string patterns relevant to your project.
  • 📄 Flexible URL input – Start with a single text file containing one URL, then expand to a larger list as your audit scope grows.

5. How to Run

  1. Download the ZIP package containing all scripts.
  2. Update DB_PATH and ROOT_PATH in settings.py to match your local directory.
  3. Install dependencies:
    pip install requests beautifulsoup4 lxml pandas openpyxl
  4. Run each script from the terminal as per your audit workflow.

6. Download

📥 Download ZIP of Python Webpage Auditor V1 📥 Download ZIP of Python Webpage Auditor V2

↑ Back to table of contents

Part 2: Analyzing the Collected Data

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.

Part 2A: SQLite Analysis

Practical SEO checks you can run from your SQLite database.

  • Store your crawl in pages (raw HTML) and summaries in page_summary.
  • Keep your Python script the same—only swap the query line to answer a specific SEO question.
  • Workflow: fetch → summarize → analyze → export. Fix issues, recrawl, re-run.

1) Missing or Too-Short <title> (active example)

  • Why: Titles <~20 chars or missing underperform on CTR and clarity.
  • Query (on 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;
  • Fix: Write unique, descriptive titles (~50–60 chars) aligned to intent/keyword.

2) Canonical Mismatch vs. Actual URL

  • Why: Wrong canonicals split signals and cause duplicate confusion.
  • Query (on page_summary):
SELECT url, canonical_url
FROM page_summary
WHERE canonical_url IS NOT NULL
  AND canonical_url != url;
  • Fix: Point rel="canonical" to the preferred, crawlable URL.

3) GA4 / Analytics Not Present

  • Why: Missing analytics = lost engagement and conversion data.
  • Query (on pages):
SELECT url
FROM pages
WHERE html NOT LIKE '%G-%'      -- quick GA4 id presence check
   OR html NOT LIKE '%gtag(';
  • Fix: Add GA4 snippet in the base template; validate on key templates.

4) Extremely Short Pages (Possible Thin Content)

  • Why: Very small HTML often indicates placeholders or thin pages.
  • Query (on pages):
SELECT url, LENGTH(html) AS bytes
FROM pages
ORDER BY LENGTH(html)
LIMIT 20;
  • Fix: Enrich or consolidate; align with search intent and internal links.

5) Missing Meta Description

  • Why: Not a ranking factor, but boosts CTR and snippet quality.
  • Query (on pages):
SELECT url
FROM pages
WHERE html NOT LIKE '%<meta name="description"%';
  • Fix: Add unique, compelling 120–160 char descriptions summarizing value.

6) Duplicate Titles Across Pages

  • Why: Duplicate signals dilute relevance and reduce discoverability.
  • Query (on 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;
  • Fix: Differentiate titles to reflect each page’s unique topic/intent.

7) Empty or Duplicate H1s

  • Why: H1 conveys primary on-page focus; keep one clear H1 per page.
  • Queries (on 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;
  • Fix: Ensure one descriptive H1 aligned with title and query intent.

8) Broken Internal Links (If Captured)

  • Why: Broken links waste crawl budget and harm UX.
  • Example shape (on page_summary):
SELECT url, broken_link
FROM page_summary
WHERE broken_link IS NOT NULL;
  • Fix: Update or remove; add redirects where appropriate.

How to Use This Section

  • Swap the query in your existing analysis script for any check above.
  • Inspect the output URLs and prioritize high-impact templates and money pages.
  • Fix issues, recrawl, and re-run the same query to ensure counts drop to zero.
  • Export from page_summary to Excel/CSV for progress tracking.

↑ Back to table of contents


Part 2B: MySQL Analysis — SEO Audit Queries

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.

Note: These queries identify potential issues, not confirmed SEO errors. Review the reported pages before making changes. They do not modify stored records.

1. Missing or short page titles

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;

↑ Back to contents

2. Missing or short meta descriptions

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;

↑ Back to contents

3. GA4 tracking: present versus missing

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;

↑ Back to contents

4. List pages without the GA4 identifier

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;

↑ Back to contents

5. Find unusually small HTML documents

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;

↑ Back to contents

6. Images missing alt attributes

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'
);

↑ Back to contents

7. Missing viewport meta tags

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'
   );

↑ Back to contents

7a. Presence of un-wanted string

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'
   );

↑ Back to contents

8. Missing canonical link tags

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'
   );

↑ Back to contents

9. Canonical directory or filename mismatch

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;

↑ Back to contents

Understanding the canonical mismatch result

FieldFetched URLCanonical URL
Directorypython (dir1)python2 (dir2)
Filenameai-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.

How to use the results

  1. Run a query in phpMyAdmin or from a Python MySQL connection.
  2. Review the returned URLs and inspect their fetched HTML.
  3. Correct issues in the original pages or common templates.
  4. Fetch the pages again, then rerun the queries to verify the results.

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.

↑ Back to table of contents

Part 2C: Excel Export and Analysis

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.

Export the page summary

  1. Run fetch_store.py to save the webpage HTML in pages.
  2. Run page_summary.py to create or refresh the extracted values in page_summary.
  3. Run page_summary_excel.py to write the summary records to Excel.
  4. Open the exported workbook and use Excel filters to review titles, descriptions, canonical URLs, headings, and other available summary fields.

Useful Excel review tasks

  • Missing information: Filter blank title, description, or canonical fields.
  • Possible duplicates: Sort or filter repeated titles and headings to identify pages needing a closer look.
  • Prioritize fixes: Add a review-status column in your working copy and track which URLs have been corrected.

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 table of contents




↑ Back to top / Table of contents

Sqlite Beatutifulsoup Simple Webpage Auditor Create XML Sitemap in Python



Subscribe to our YouTube Channel here



plus2net.com




Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer