From a8d475afb0462d9bcf0bbaae06517b5f4f578d92 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Fri, 31 Jan 2025 01:38:48 +0200 Subject: [PATCH] feat(parser): Make all returned html as TextHandler So you can do regex on raw html if wanted etc... --- scrapling/parser.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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