Parses HTML or XML content and returns the parsed document tree. Args: content: The HTML or XML content to parse, either as a string or bytes. options: Parsing options that specify whether to parse as HTML or XML. Returns: A TreeDom object representing the pars
(
content: typing.Union[str, bytes],
options: typing.Union[
_rustlib.HtmlOptions,
_rustlib.XmlOptions,
typing.Literal["html"],
typing.Literal["xml"],
] = "html",
)
| 121 | |
| 122 | |
| 123 | def parse( |
| 124 | content: typing.Union[str, bytes], |
| 125 | options: typing.Union[ |
| 126 | _rustlib.HtmlOptions, |
| 127 | _rustlib.XmlOptions, |
| 128 | typing.Literal["html"], |
| 129 | typing.Literal["xml"], |
| 130 | ] = "html", |
| 131 | ) -> TreeDom: |
| 132 | """ |
| 133 | Parses HTML or XML content and returns the parsed document tree. |
| 134 | |
| 135 | Args: |
| 136 | content: The HTML or XML content to parse, either as a string or bytes. |
| 137 | options: Parsing options that specify whether to parse as HTML or XML. |
| 138 | |
| 139 | Returns: |
| 140 | A TreeDom object representing the parsed document tree. |
| 141 | """ |
| 142 | parser = Parser(options) |
| 143 | parser.process(content) |
| 144 | return parser.finish().into_dom() |
| 145 | |
| 146 | |
| 147 | def parse_file( |