Implementation:ALwrity ALwrity OnPageSEOService
| Knowledge Sources | |
|---|---|
| Domains | SEO, Web_Analysis, Blog_Writer |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for on-page SEO analysis of a web page's HTML — meta tags, technical elements, and content quality — provided by the ALwrity SEO tools subsystem.
Description
The OnPageSEOService class fetches a page's HTML via aiohttp, parses it with BeautifulSoup, and runs three analysis passes: _analyze_meta_tags (title length, meta description, viewport, charset, robots, Open Graph, Twitter card), _analyze_technical (canonical tag, H1 count, schema markup), and _analyze_content (heading structure, image alt text, link analysis, content length). Each pass returns a dict with a score (0-100), a list of issues, and per-element details. The combined result gives a complete on-page SEO audit that the blog writer pipeline uses to optimise generated content before publishing.
Usage
Import this service when:
- The blog writer pipeline needs to audit generated or published content for SEO issues.
- An SEO analysis pipeline needs meta-tag, technical, and content scores.
- Actionable issue lists are needed for SEO recommendations.
Code Reference
Source Location
- Repository: ALwrity
- File: backend/services/seo_tools/on_page_seo_service.py (L16-150)
Signature
class OnPageSEOService:
"""Service for comprehensive on-page SEO analysis."""
def __init__(self):
self.service_name = "on_page_seo_analyzer"
async def _fetch_page(self, url: str) -> tuple[Optional[str], int]:
"""Fetch page content via aiohttp (returns (html, status_code))."""
def _analyze_meta_tags(self, soup: BeautifulSoup) -> Dict[str, Any]:
"""Analyze meta tags (title, description, viewport, OG, Twitter card)."""
def _analyze_technical(self, soup: BeautifulSoup, url: str) -> Dict[str, Any]:
"""Analyze technical SEO (canonical, H1, schema markup)."""
def _analyze_content(self, soup: BeautifulSoup) -> Dict[str, Any]:
"""Analyze content quality (headings, images, links, word count)."""
Import
from services.seo_tools.on_page_seo_service import OnPageSEOService
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| url | str | Yes (fetch) | Page URL to fetch and analyse |
| soup | BeautifulSoup | Yes (analyse) | Parsed HTML from _fetch_page |
Outputs
| Name | Type | Description |
|---|---|---|
| _fetch_page | tuple[Optional[str], int] | (HTML string, HTTP status code) |
| _analyze_meta_tags | Dict[str, Any] | title_length, meta_description_length, has_viewport, charset, robots_meta, og_tags, twitter_card, score, issues |
| _analyze_technical | Dict[str, Any] | canonical_tag, h1_count, schema_markup, score, issues |
| _analyze_content | Dict[str, Any] | heading_structure, image_alt_coverage, link_analysis, word_count, score, issues |
Usage Examples
Auditing a page
from services.seo_tools.on_page_seo_service import OnPageSEOService
from bs4 import BeautifulSoup
service = OnPageSEOService()
html, status = await service._fetch_page("https://example.com/blog/post-1")
if status == 200:
soup = BeautifulSoup(html, "html.parser")
meta = service._analyze_meta_tags(soup)
tech = service._analyze_technical(soup, "https://example.com/blog/post-1")
content = service._analyze_content(soup)
print(f"Meta score: {meta['score']}, Tech score: {tech['score']}, Content score: {content['score']}")
for issue in meta["issues"] + tech["issues"] + content["issues"]:
print(f" - {issue}")