From d262bea2cbde39915ced6b35cff38d034ae255d4 Mon Sep 17 00:00:00 2001 From: Kibzik Date: Mon, 10 Apr 2023 19:16:33 +0300 Subject: [PATCH] try except text replacer --- src/html_presets_processor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/html_presets_processor.py b/src/html_presets_processor.py index 8905c47..5afe214 100644 --- a/src/html_presets_processor.py +++ b/src/html_presets_processor.py @@ -197,10 +197,13 @@ class HtmlPresetsProcessor: @staticmethod def _replace_text(**kwargs): - if re.search(re.compile(kwargs["rule"]["condition"]["text"]), kwargs["found_tag"].string): - new_text = re.sub(re.compile( - kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], kwargs["found_tag"].string) - kwargs["found_tag"].string.replace_with(new_text) + try: + if re.search(re.compile(kwargs["rule"]["condition"]["text"]), kwargs["found_tag"].string): + new_text = re.sub(re.compile( + kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], kwargs["found_tag"].string) + kwargs["found_tag"].string.replace_with(new_text) + except TypeError: + pass def process_tags(self, body_tag: BeautifulSoup,