1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2026-02-03 12:36:56 +00:00

[core] utils: fix some cases

This commit is contained in:
Allen
2024-12-05 00:43:15 +01:00
parent ec3a0927c4
commit c49aa772cc
2 changed files with 11 additions and 14 deletions

View File

@@ -430,10 +430,14 @@ def get_element_text_and_html_by_tag(tag, html):
return its' content (text) and the whole element (html)
"""
def find_or_raise(haystack, needle, exc):
try:
with contextlib.suppress(ValueError):
return haystack.index(needle)
except ValueError:
raise exc
with contextlib.suppress(ValueError):
return haystack.index(needle.upper())
raise exc
closing_tag = f'</{tag}>'
whole_start = find_or_raise(
html, f'<{tag}', compat_HTMLParseError(f'opening {tag} tag not found'))