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): handle responses with empty body

Karim shoairdac854a12930
diff --git a/scrapling/parser.py b/scrapling/parser.py
index f7da3a9..8e9704d 100644
--- a/scrapling/parser.py
+++ b/scrapling/parser.py
@@ -138,7 +138,7 @@ class Selector(SelectorsGeneration):
default_doctype=True,
strip_cdata=(not keep_cdata),
)
- self._root = cast(HtmlElement, fromstring(body, parser=parser, base_url=url or None))
+ self._root = cast(HtmlElement, fromstring(body or "<html/>", parser=parser, base_url=url or None))
self._raw_body = content
else: