🕷️ 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
Python aiai-scrapingautomationcrawlercrawlingcrawling-pythondatadata-extractionmcpmcp-serverplaywrightpythonscrapingselectorsstealthweb-scraperweb-scrapingweb-scraping-pythonwebscrapingxpath
feat: Make `.body` return the passed content as it is without any processing
Karim shoairce4fc31f2c30
diff --git a/scrapling/parser.py b/scrapling/parser.pyindex 07576b0..409e09d 100644--- a/scrapling/parser.py+++ b/scrapling/parser.py@@ -132,8 +132,7 @@ class Selector(SelectorsGeneration):strip_cdata=(not keep_cdata),)self._root = fromstring(body, parser=parser, base_url=url)-- self._raw_body = body.decode()+ self._raw_body = contentelse:# All HTML types inherit from HtmlMixin so this to check for all at once@@ -342,7 +341,10 @@ class Selector(SelectorsGeneration):"""Return the inner HTML code of the element"""return TextHandler(tostring(self._root, encoding=self.encoding, method="html", with_tail=False))- body = html_content+ @property+ def body(self):+ """Return the raw body of the current `Selector` without any processing. Useful for binary and non-HTML requests."""+ return self._raw_bodydef prettify(self) -> TextHandler:"""Return a prettified version of the element's inner html-code"""@@ -934,7 +936,7 @@ class Selector(SelectorsGeneration):# Operations on text functionsdef json(self) -> Dict:"""Return JSON response if the response is jsonable otherwise throws error"""- if self._raw_body:+ if self._raw_body and isinstance(self._raw_body, str):return TextHandler(self._raw_body).json()elif self.text:return self.text.json()