"""
HTML Parser
Part of SOVEREIGN PYTHON LLM ENGINE
Parse HTML documents and extract clean text.
"""
from typing import Any
from pathlib import Path
from dataclasses import dataclass
import re
@dataclass
class HTMLDocument:
"""Parsed HTML document"""
text: str
title: str | None
links: list[dict[str, str]]
images: list[dict[str, str]]
metadata: dict[str, Any]
class HTMLParser:
"""
HTML document parser using BeautifulSoup.
Extracts:
- Clean text (no tags)
- Title
- Links
- Images
- Meta tags
"""
def __init__(self, remove_scripts: bool = True, remove_styles: bool = True):
"""
Initialize HTML parser.
Args:
remove_scripts: Remove