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): Make all returned html as TextHandler

Karim shoaira8d475afb046
diff --git a/scrapling/parser.py b/scrapling/parser.py
index 86c9f3e..d3ec663 100644
--- a/scrapling/parser.py
+++ b/scrapling/parser.py
@@ -259,18 +259,18 @@ class Adaptor(SelectorsGeneration):
return self.__attributes
@property
- def html_content(self) -> str:
+ def html_content(self) -> TextHandler:
"""Return the inner html code of the element"""
- return etree.tostring(self._root, encoding='unicode', method='html', with_tail=False)
+ return TextHandler(etree.tostring(self._root, encoding='unicode', method='html', with_tail=False))
@property
- def body(self) -> str:
+ def body(self) -> TextHandler:
"""Return raw HTML code of the element/page without any processing when possible or return `Adaptor.html_content`"""
- return self.__raw_body or self.html_content
+ return TextHandler(self.__raw_body) or self.html_content
- def prettify(self) -> str:
+ def prettify(self) -> TextHandler:
"""Return a prettified version of the element's inner html-code"""
- return etree.tostring(self._root, encoding='unicode', pretty_print=True, method='html', with_tail=False)
+ return TextHandler(etree.tostring(self._root, encoding='unicode', pretty_print=True, method='html', with_tail=False))
def has_class(self, class_name: str) -> bool:
"""Check if element has a specific class