aidputils.agents.tools.http.html_parser¶
Custom HTML Parser for HTTP Tool.
Provides HTML parsing and CSS selector extraction using Python’s stdlib html.parser, replacing the bs4 (BeautifulSoup4) dependency.
Supports: - Basic CSS selectors: tag, .class, #id, tag.class, tag#id - Text extraction with tag stripping - Element selection for response optimization
- class aidputils.agents.tools.http.html_parser.HTMLNode(tag: str, attrs: List[Tuple[str, str | None]] = None)[source]¶
Bases:
objectRepresents an HTML element node.
- tag¶
- attrs¶
- text: str¶
- matches_selector(selector: str) bool[source]¶
Check if this node matches a CSS selector.
Supports: - tag: matches tag name - .class: matches class - #id: matches id - tag.class: matches tag with class - tag#id: matches tag with id - .class1.class2: matches multiple classes
- class aidputils.agents.tools.http.html_parser.SimpleHTMLParser[source]¶
Bases:
HTMLParserSimple HTML parser that builds a basic DOM tree.
Uses Python’s stdlib html.parser for parsing.
Initialize and reset this instance.
If convert_charrefs is True (the default), all character references are automatically converted to the corresponding Unicode characters.
- aidputils.agents.tools.http.html_parser.parse_html(html: str) HTMLNode[source]¶
Parse HTML string into a node tree.
- aidputils.agents.tools.http.html_parser.select_elements(html: str, selector: str) List[HTMLNode][source]¶
Select elements matching a CSS selector.
- Parameters:
html – HTML string to parse
selector – CSS selector (tag, .class, #id, or combinations)
- Returns:
List of matching HTMLNode elements
- aidputils.agents.tools.http.html_parser.get_text(html: str, separator: str = ' ', strip: bool = True) str[source]¶
Extract all text content from HTML, stripping tags.
- Parameters:
html – HTML string
separator – String to join text segments
strip – Whether to strip whitespace
- Returns:
Plain text content