fix(parser): Make html_content and prettify return strings not bytes (depends on the encoding)
This commit is contained in:
+13
-9
@@ -339,7 +339,10 @@ class Selector(SelectorsGeneration):
|
|||||||
@property
|
@property
|
||||||
def html_content(self) -> TextHandler:
|
def html_content(self) -> TextHandler:
|
||||||
"""Return the inner HTML code of the element"""
|
"""Return the inner HTML code of the element"""
|
||||||
return TextHandler(tostring(self._root, encoding=self.encoding, method="html", with_tail=False))
|
content = tostring(self._root, encoding=self.encoding, method="html", with_tail=False)
|
||||||
|
if isinstance(content, bytes):
|
||||||
|
content = content.decode("utf-8")
|
||||||
|
return TextHandler(content)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def body(self):
|
def body(self):
|
||||||
@@ -348,15 +351,16 @@ class Selector(SelectorsGeneration):
|
|||||||
|
|
||||||
def prettify(self) -> TextHandler:
|
def prettify(self) -> TextHandler:
|
||||||
"""Return a prettified version of the element's inner html-code"""
|
"""Return a prettified version of the element's inner html-code"""
|
||||||
return TextHandler(
|
content = tostring(
|
||||||
tostring(
|
self._root,
|
||||||
self._root,
|
encoding=self.encoding,
|
||||||
encoding=self.encoding,
|
pretty_print=True,
|
||||||
pretty_print=True,
|
method="html",
|
||||||
method="html",
|
with_tail=False,
|
||||||
with_tail=False,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
if isinstance(content, bytes):
|
||||||
|
content = content.decode("utf-8")
|
||||||
|
return TextHandler(content)
|
||||||
|
|
||||||
def has_class(self, class_name: str) -> bool:
|
def has_class(self, class_name: str) -> bool:
|
||||||
"""Check if the element has a specific class
|
"""Check if the element has a specific class
|
||||||
|
|||||||
Reference in New Issue
Block a user