From 942aa08c8502c1eaa8c611f349e9db3f6bfb9baf Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Sun, 3 Nov 2024 13:00:23 +0200 Subject: [PATCH] Handling JSON responses better --- scrapling/parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scrapling/parser.py b/scrapling/parser.py index 2dd4f66..57a7529 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -601,7 +601,10 @@ class Adaptor(SelectorsGeneration): # Operations on text functions def json(self) -> Dict: """Return json response if the response is jsonable otherwise throws error""" - return self.text.json() + if self.text: + return self.text.json() + else: + return self.get_all_text(strip=True).json() def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True) -> 'List[str]': """Apply the given regex to the current text and return a list of strings with the matches.