fix(parser): Solve the ignored elements children issue while keeping speed

solves #61
This commit is contained in:
Karim shoair
2025-07-27 05:34:48 +03:00
parent d1aa0be6e4
commit 93bd131bb6
+12 -6
View File
@@ -291,15 +291,21 @@ class Adaptor(SelectorsGeneration):
:return: A TextHandler
"""
ignored_elements = set()
if ignore_tags:
for tag in ignore_tags:
for element in self._root.xpath(f".//{tag}"):
ignored_elements.add(element)
ignored_elements.update(element.xpath(".//*"))
_all_strings = []
for node in self._root.xpath(".//*"):
if node.tag not in ignore_tags:
if node not in ignored_elements:
text = node.text
if text and type(text) is str:
if valid_values and text.strip():
_all_strings.append(text if not strip else text.strip())
else:
_all_strings.append(text if not strip else text.strip())
if text and isinstance(text, str):
processed_text = text.strip() if strip else text
if not valid_values or processed_text.strip():
_all_strings.append(processed_text)
return TextHandler(separator.join(_all_strings))