try except text replacer

This commit is contained in:
Kibzik
2023-04-10 19:16:33 +03:00
parent 6434d1014e
commit d262bea2cb

View File

@@ -197,10 +197,13 @@ class HtmlPresetsProcessor:
@staticmethod @staticmethod
def _replace_text(**kwargs): def _replace_text(**kwargs):
try:
if re.search(re.compile(kwargs["rule"]["condition"]["text"]), kwargs["found_tag"].string): if re.search(re.compile(kwargs["rule"]["condition"]["text"]), kwargs["found_tag"].string):
new_text = re.sub(re.compile( new_text = re.sub(re.compile(
kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], kwargs["found_tag"].string) kwargs["rule"]["condition"]["text"]), kwargs["rule"]["text_to_replace"], kwargs["found_tag"].string)
kwargs["found_tag"].string.replace_with(new_text) kwargs["found_tag"].string.replace_with(new_text)
except TypeError:
pass
def process_tags(self, def process_tags(self,
body_tag: BeautifulSoup, body_tag: BeautifulSoup,