I have below HTML blocks, that are generated by pdftotext using the -bbox-layout option:
<flow>
<block xMin="21.600000" yMin="86.356000" xMax="178.647000" yMax="116.233001">
<line xMin="21.600000" yMin="86.356000" xMax="178.647000" yMax="101.833000">
<word xMin="21.600000" yMin="86.356000" xMax="178.647000" yMax="101.833000">
My text string located here!</word>
</line>
</block>
</flow>
[...]
<flow>
<block xMin="223.560000" yMin="323.675000" xMax="345.563500" yMax="339.855500">
<line xMin="223.560000" yMin="323.675000" xMax="345.563500" yMax="339.855500">
<word xMin="223.560000" yMin="323.675000" xMax="316.836500" yMax="339.855500">Another string
</word>
<word xMin="320.022000" yMin="323.675000" xMax="345.563500" yMax="339.855500">And another!</word>
</line>
</block>
</flow>
Now, I am trying to dynamically parse the above structure, and get each <block>[...]</block> content, where the values xMin and xMax is between two numbers.
Imagine I have below numbers:
areas[0] = (100, 0, 200, 792)
areas[1] = (200, 0, 612, 792)
with open(path_to_html_document) as html_file:
parsed_html = BeautifulSoup(html_file)
for (i, area) in enumerate(areas):
xMinValue, xMaxValue = areas[i][0], areas[i][2]
block_tags = parsed_html.find_all(
"block", attrs={"xMin": xMinValue, "xMax": xMaxValue})
print(block_tags)
Above code doesn't return anything, because there are no matching tags. The find_all() search for exact matches for block tags with the specific numbers - but I am trying to search for block tags, where xMin and xMax is:
areas[0] is between 100 and 200
areas[1] is between 200 and 612
is this possible with BeautifulSoup?