Pyjo.DOM.HTML - HTML/XML engine¶
from Pyjo.DOM.HTML import HTML
# Turn HTML into DOM tree
html = HTML()
html.parse('<div><p id="a">Test</p><p id="b">123</p></div>')
tree = html.tree
# Or import the module, as in Google Python Style Guide
import Pyjo.DOM.HTML
# Turn HTML into DOM tree
html = Pyjo.DOM.HTML.new()
html.parse('<div><p id="a">Test</p><p id="b">123</p></div>')
tree = html.tree
Pyjo.DOM.HTML is the HTML/XML engine used by Pyjo.DOM, based on
the HTML Living Standard and the
Extensible Markup Language (XML) 1.0.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojo::DOM::HTML of Mojolicious 9.53.
Functions¶
- class Pyjo.DOM.HTML.Pyjo_DOM_HTML(tree: Tree | None = None, **kwargs: bool | None)[source]¶
Pyjo.DOM.HTMLinherits all methods fromPyjo.Baseand implements the following new ones.- parse(html: Anything) Self[source]¶
html = html.parse('<foo bar="baz">I ♥ Pyjoyment!</foo>')
Parse HTML/XML fragment. Bytes are a whole document, whose encoding is found as the HTML Living Standard sniffs it: a byte order mark, the
encodingof an XML declaration, a<meta charset>or<meta http-equiv="Content-Type">in the first 1024 bytes, andUTF-8by default.
- tag(name: str, content: str | Callable[[], str] | None = None, /, **attrs: Any) Self[source]¶
html = html.tag('div', 'safe content', id='foo')
Generate HTML/XML tag.
- tree: Tree¶
tree = html.tree html.tree = ['root']
Document Object Model. Note that this structure should only be used very carefully since it is very dynamic.
- Pyjo.DOM.HTML.tag_to_html(name: str, content: str | Callable[[], str] | None = None, /, **attrs: Any) str[source]¶
string = tag_to_html('div', 'safe content', id='foo')
Generate HTML/XML tag and render it right away. This is a significantly faster alternative to
tag()for template systems that have to generate a lot of tags.