From 4acdf9e191243d483c366efaccd4012cca7ed032 Mon Sep 17 00:00:00 2001 From: Thanos <111999343+Sachaa-Thanasius@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:44:43 -0400 Subject: [PATCH] Catch ValueError in clean_fandom_page when looking for subheadings. --- exts/fandom_wiki.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/exts/fandom_wiki.py b/exts/fandom_wiki.py index 2bd4c0c..9e4e1cb 100644 --- a/exts/fandom_wiki.py +++ b/exts/fandom_wiki.py @@ -104,14 +104,24 @@ def clean_fandom_page(element: etree._Element) -> etree._Element: # type: ignor toc = element.find(".//div[@id='toc']") if toc is not None: - if element.index(toc) > summary_end_index: - summary_end_index = element.index(toc) + try: + index = element.index(toc) + except ValueError: + pass + else: + if index > summary_end_index: + summary_end_index = index toc.getparent().remove(toc) # type: ignore [reportOptionalMemberAccess] subheading = element.find(".//h2") if subheading is not None: - if element.index(subheading) > summary_end_index: - summary_end_index = element.index(subheading) + try: + index = element.index(subheading) + except ValueError: + pass + else: + if index > summary_end_index: + summary_end_index = index subheading.getparent().remove(subheading) # type: ignore [reportOptionalMemberAccess] if summary_end_index != 0: