diff --git a/scrapling/parser.py b/scrapling/parser.py index 1afce3a..5743306 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -788,7 +788,7 @@ def json(self) -> Dict: return self.get_all_text(strip=True).json() def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, - clean_match: bool = False, case_sensitive: bool = False) -> 'List[str]': + clean_match: bool = False, case_sensitive: bool = False) -> TextHandlers: """Apply the given regex to the current text and return a list of strings with the matches. :param regex: Can be either a compiled regular expression or a string. @@ -799,7 +799,7 @@ def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, return self.text.re(regex, replace_entities, clean_match, case_sensitive) def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True, - clean_match: bool = False, case_sensitive: bool = False) -> Union[str, None]: + clean_match: bool = False, case_sensitive: bool = False) -> TextHandler: """Apply the given regex to text and return the first match if found, otherwise return the default value. :param regex: Can be either a compiled regular expression or a string. @@ -1048,7 +1048,7 @@ def css(self, selector: str, identifier: str = '', auto_save: bool = False, perc return self.__class__(flatten(results)) def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, - clean_match: bool = False, case_sensitive: bool = False) -> 'List[str]': + clean_match: bool = False, case_sensitive: bool = False) -> TextHandlers[TextHandler]: """Call the ``.re()`` method for each element in this list and return their results flattened as List of TextHandler. @@ -1060,10 +1060,10 @@ def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, results = [ n.text.re(regex, replace_entities, clean_match, case_sensitive) for n in self ] - return flatten(results) + return TextHandlers(flatten(results)) def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True, - clean_match: bool = False, case_sensitive: bool = False) -> Union[str, None]: + clean_match: bool = False, case_sensitive: bool = False) -> TextHandler: """Call the ``.re_first()`` method for each element in this list and return the first result or the default value otherwise.