fix: Fixes for multiple encoding issues (#80 & #81 )

This commit is contained in:
Karim shoair
2025-09-14 20:20:29 +03:00
parent 68615b2347
commit 67ca139ff9
4 changed files with 101 additions and 144 deletions
+4 -4
View File
@@ -74,7 +74,7 @@ class Selector(SelectorsGeneration):
self,
content: Optional[str | bytes] = None,
url: Optional[str] = None,
encoding: str = "utf8",
encoding: str = "utf-8",
huge_tree: bool = True,
root: Optional[HtmlElement] = None,
keep_comments: Optional[bool] = False,
@@ -116,7 +116,7 @@ class Selector(SelectorsGeneration):
if isinstance(content, str):
body = content.strip().replace("\x00", "").encode(encoding) or b"<html/>"
elif isinstance(content, bytes):
body = content.replace(b"\x00", b"").strip()
body = content.replace(b"\x00", b"")
else:
raise TypeError(f"content argument must be str or bytes, got {type(content)}")
@@ -340,7 +340,7 @@ class Selector(SelectorsGeneration):
@property
def html_content(self) -> TextHandler:
"""Return the inner HTML code of the element"""
return TextHandler(tostring(self._root, encoding="unicode", method="html", with_tail=False))
return TextHandler(tostring(self._root, encoding=self.encoding, method="html", with_tail=False))
body = html_content
@@ -349,7 +349,7 @@ class Selector(SelectorsGeneration):
return TextHandler(
tostring(
self._root,
encoding="unicode",
encoding=self.encoding,
pretty_print=True,
method="html",
with_tail=False,