From f37538320fae3dec5145a870d3d16f16fb8fb4ca Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Thu, 30 Jan 2025 23:05:10 +0200 Subject: [PATCH] feat(parser): adding `below_elements` method --- scrapling/parser.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scrapling/parser.py b/scrapling/parser.py index 5743306..cadfa82 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -19,7 +19,7 @@ from scrapling.core.storage_adaptors import (SQLiteStorageSystem, StorageSystemMixin, _StorageTools) from scrapling.core.translator import HTMLTranslator from scrapling.core.utils import (clean_spaces, flatten, html_forbidden, - is_jsonable, log) + is_jsonable, log, lru_cache) class Adaptor(SelectorsGeneration): @@ -284,6 +284,13 @@ class Adaptor(SelectorsGeneration): """Return the direct parent of the element or ``None`` otherwise""" return self.__handle_element(self._root.getparent()) + @property + @lru_cache(None, True) + def below_elements(self) -> 'Adaptors[Adaptor]': + """Return all elements under the current element in the DOM tree""" + below = self._root.xpath('.//*') + return self.__handle_elements(below) + @property def children(self) -> 'Adaptors[Adaptor]': """Return the children elements of the current element or empty list otherwise"""