From 009c2914aa323091a58b9a0e1f8b8b18e2f60f25 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Tue, 5 Nov 2024 22:59:47 +0200 Subject: [PATCH] Fixing `re_first` logic in `Adaptors` type --- scrapling/parser.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scrapling/parser.py b/scrapling/parser.py index 2d0ebf1..3416ec6 100644 --- a/scrapling/parser.py +++ b/scrapling/parser.py @@ -867,17 +867,18 @@ class Adaptors(List[Adaptor]): def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True): """Call the ``.re_first()`` method for each element in this list and return - their results flattened as List of TextHandler. + the first result or the default value otherwise. :param regex: Can be either a compiled regular expression or a string. :param default: The default value to be returned if there is no match :param replace_entities: if enabled character entity references are replaced by their corresponding character """ - results = [ - n.text.re_first(regex, default, replace_entities) for n in self - ] - return flatten(results) + for n in self: + result = n.re_first(regex, None, replace_entities) + if result: + return result + return default # def __getattr__(self, name): # if name in dir(self.__class__):