feat(parser): adding below_elements method

This commit is contained in:
Karim shoair
2025-01-30 23:05:10 +02:00
parent ae60c2c0ad
commit f37538320f
+8 -1
View File
@@ -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"""