in obelics/processors/dom_tree_simplificator.py [0:0]
def _remove_empty_leaves(self, selectolax_tree):
"""
Function used to remove empty leaves iteratively, so it also ends up also removing nodes
that are higher up in the tree.
"""
modification = True
while modification:
nodes_to_remove = [
node
for node in selectolax_tree.root.traverse()
if (
(node.tag not in MEDIA_CONTAIN_INTERESTING_ATTRIBUTES_SET)
and (not [child for child in node.iter()])
and (not node.text().strip())
and (node.tag != "html")
)
or (
(node.tag in MEDIA_CONTAIN_INTERESTING_ATTRIBUTES_SET)
and not get_media_src(node)
)
]
if nodes_to_remove:
for node in nodes_to_remove:
node.decompose(recursive=False)
else:
modification = False
return selectolax_tree