Karim shoair commited on
Commit
a5fdbbe
·
1 Parent(s): 1bce6ce

Handling JSON responses better

Browse files
Files changed (1) hide show
  1. scrapling/parser.py +4 -1
scrapling/parser.py CHANGED
@@ -601,7 +601,10 @@ class Adaptor(SelectorsGeneration):
601
  # Operations on text functions
602
  def json(self) -> Dict:
603
  """Return json response if the response is jsonable otherwise throws error"""
604
- return self.text.json()
 
 
 
605
 
606
  def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True) -> 'List[str]':
607
  """Apply the given regex to the current text and return a list of strings with the matches.
 
601
  # Operations on text functions
602
  def json(self) -> Dict:
603
  """Return json response if the response is jsonable otherwise throws error"""
604
+ if self.text:
605
+ return self.text.json()
606
+ else:
607
+ return self.get_all_text(strip=True).json()
608
 
609
  def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True) -> 'List[str]':
610
  """Apply the given regex to the current text and return a list of strings with the matches.