From d1a2ecd3412604a65dea67455f3d72b414e3ae4d Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Sat, 2 Aug 2025 04:08:14 +0300 Subject: [PATCH] perf: optimize `get_all_text` and adaptive logic by another 10% --- scrapling/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scrapling/parser.py b/scrapling/parser.py index e3d30c6..84e7876 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -323,7 +323,7 @@ class Selector(SelectorsGeneration): ignored_elements.update(set(element.iterchildren())) _all_strings = [] - for node in self._root.xpath(".//*"): + for node in self._root.iter(): if node not in ignored_elements: text = node.text if text and isinstance(text, str): @@ -496,7 +496,7 @@ class Selector(SelectorsGeneration): if issubclass(type(element), HtmlElement): element = _StorageTools.element_to_dict(element) - for node in self._root.xpath(".//*"): + for node in self._root.iter("*"): # Collect all elements in the page, then for each element get the matching score of it against the node. # Hence: the code doesn't stop even if the score was 100% # because there might be another element(s) left in page with the same score