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

fix(parser): An encoding issue with converting bytes to string on some encoding types

Karim shoair63a46a8e0bec
diff --git a/scrapling/parser.py b/scrapling/parser.py
index f0b9e54..776dd55 100644
--- a/scrapling/parser.py
+++ b/scrapling/parser.py
@@ -341,7 +341,7 @@ class Selector(SelectorsGeneration):
"""Return the inner HTML code of the element"""
content = tostring(self._root, encoding=self.encoding, method="html", with_tail=False)
if isinstance(content, bytes):
- content = content.decode("utf-8")
+ content = content.strip().decode(self.encoding)
return TextHandler(content)
@property
@@ -359,7 +359,7 @@ class Selector(SelectorsGeneration):
with_tail=False,
)
if isinstance(content, bytes):
- content = content.decode("utf-8")
+ content = content.strip().decode(self.encoding)
return TextHandler(content)
def has_class(self, class_name: str) -> bool: