MCPcopy
hub / github.com/django/django / parse_html

Function parse_html

django/test/html.py:258–273  ·  view source on GitHub ↗

Take a string that contains HTML and turn it into a Python object structure that can be easily compared against other HTML on semantic equivalence. Syntactical differences like which quotation is used on arguments will be ignored.

(html)

Source from the content-addressed store, hash-verified

256
257
258def parse_html(html):
259 """
260 Take a string that contains HTML and turn it into a Python object structure
261 that can be easily compared against other HTML on semantic equivalence.
262 Syntactical differences like which quotation is used on arguments will be
263 ignored.
264 """
265 parser = Parser()
266 parser.feed(html)
267 parser.close()
268 document = parser.root
269 document.finalize()
270 # Removing ROOT element if it's not necessary
271 if len(document.children) == 1 and not isinstance(document.children[0], str):
272 document = document.children[0]
273 return document

Callers 10

assert_and_parse_htmlFunction · 0.90
test_html_parserMethod · 0.90
test_void_elementsMethod · 0.90
test_html_containMethod · 0.90
test_countMethod · 0.90
test_parsing_errorsMethod · 0.90

Calls 4

ParserClass · 0.70
feedMethod · 0.45
closeMethod · 0.45
finalizeMethod · 0.45

Tested by 10

assert_and_parse_htmlFunction · 0.72
test_html_parserMethod · 0.72
test_void_elementsMethod · 0.72
test_html_containMethod · 0.72
test_countMethod · 0.72
test_parsing_errorsMethod · 0.72