From 9ce32794885226993153c6173fe929290aad8215 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Tue, 29 Jul 2025 22:31:03 +0300 Subject: [PATCH] fix(TextHandler): Increase speed of `clean` method 5 times --- scrapling/core/custom_types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scrapling/core/custom_types.py b/scrapling/core/custom_types.py index 358ff64..4afc926 100644 --- a/scrapling/core/custom_types.py +++ b/scrapling/core/custom_types.py @@ -116,9 +116,9 @@ class TextHandler(str): def clean(self) -> Union[str, "TextHandler"]: """Return a new version of the string after removing all white spaces and consecutive spaces""" - data = re.sub(r"[\t|\r|\n]", "", self) - data = re.sub(" +", " ", data) - return self.__class__(data.strip()) + trans_table = str.maketrans("\t\r\n", " ") + data = self.translate(trans_table) + return self.__class__(re.sub(" +", " ", data).strip()) # For easy copy-paste from Scrapy/parsel code when needed :) def get(self, default=None):