Files
omniread/tests/test_html_simple.py
Vishesh 'ironeagle' Bangotra 650d3a19e8 chore(release): 0.0.3
Squash-merge lib-standardisation: adopt repo standards across packaging,
tooling, docs, and CI.

- standardize pyproject.toml (canonical packaging, lint config, extras, GSDFC pydoclint)
- add py.typed marker, modernize type hints and Google-style docstrings
- nest generated docs under docs/lib and docs/mcp; add hand-written wiki
- adopt standard Type A PyPI CI pipeline (tag==version guard + quality gate)
- promote generated CHANGELOG.md; bump version to 0.0.3
2026-10-17 02:16:48 +05:30

51 lines
1.2 KiB
Python

from bs4 import Tag
from pydantic import BaseModel
from omniread import (
# core
Content,
# html
HTMLParser,
)
class ParsedSimpleHTML(BaseModel):
title: str | None
description: str | None
content: str | None
link: str | None
class SimpleHTMLParser(HTMLParser[ParsedSimpleHTML]):
"""
Parser focused on high-level page semantics.
"""
def parse(self) -> ParsedSimpleHTML:
soup = self._soup
meta = self.parse_meta()
content_div = soup.find("div", id="content")
link_tag: Tag | None = soup.find("a")
return ParsedSimpleHTML(
title=meta["title"],
description=meta["meta"].get("description"),
content=self.parse_div(content_div) if content_div else None,
link=self.parse_link(link_tag) if link_tag else None,
)
def test_end_to_end_html_simple(http_scraper):
content: Content = http_scraper.fetch("https://test.local/simple")
parser = SimpleHTMLParser(content)
result = parser.parse()
assert isinstance(result, ParsedSimpleHTML)
assert result.title == "Test Page"
assert result.description == "Simple test page"
assert result.content == "Hello World"
assert result.link == "https://example.com"