Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

feat(parser): adding `below_elements` method

Karim shoairf37538320fae
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"""