bug/partition_html fails parsing simple html
Describe the bug partition_html does not parse properly a valid HTML document.
To Reproduce The following html document has been fed to partition_html
<!DOCTYPE html>
<html>
<head>
<title>A page</title>
</head>
<body>
<div>
<h1>Header 1</h1>
<p>Text </p>
<h2>Header 2</h2>
<pre><b>Param1</b> = Y<br><b>Param2</b> = 1<br><b>Param3</b> = 2<br><b>Param4</b> = A<br><b>Param5</b> = A,B,C,D,E<br><b>Param6</b> = 7<br><b>Param7</b> = Five<br></pre>
</div>
</body>
</html>
Expected behavior I expected partition_html to output the following result:
Header 1
Text
Header 2
Param1 = Y
Param2 = 1
Param3 = 2
Param4 = A
Param5 = A,B,C,D,E
Param6 = 7
Param7= Five
but instead it outputs only:
Header 1
Text
Header 2
Environment Info Tested on both 0.12.3 and 0.12.2
can you please elaborate issue in details ? and also tell me which OS you can use
Related to bug/partition_html only partially extracts text of element with nested inline tag #2362
There is a bug inside HTMLDocument._parse_pages_from_element_tree() that stops parsing of an element if it encounters a section tag (div, pre) that contains a nested inline tag.
Here is test code
def test_nested_divs_containing_nested_spans():
html_str = """
<div>
Head
<div><span>Nested</span></div>
Tail
</div>
"""
html_document = HTMLDocument.from_string(html_str)
html_content = '|'.join([str(e).strip() for e in html_document.elements])
assert html_content == "Head|Nested|Tail"
Expected :'Head|Nested|Tail'
Actual :'Head|Nested'
In this case the code is encountering the nested div
<pre><b>Param1</b></pre>
The issue is in how the tail() of an element is processed and the behaviour comes from the underlying lxml etree parser
There is a partially successful PR 2483 that addresses this
This is a severe bug as it can cause large sections of an HTML document to fail to be read.
Addressed this issue in PR #2849. This issue was not related to tail text parsing failure, it was due to failure in parsing <b> tags inside container tags (like <div>, <pre>).