From 93bd131bb6945f77ece222a3110b7452254908a0 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Sun, 27 Jul 2025 05:34:48 +0300 Subject: [PATCH] fix(parser): Solve the ignored elements children issue while keeping speed solves #61 --- scrapling/parser.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scrapling/parser.py b/scrapling/parser.py index 7cb4afd..4cd070c 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -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))