diff --git a/test/test_utils.py b/test/test_utils.py index 65f28db36..6bd5e0824 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1789,6 +1789,10 @@ def test_get_element_html_by_class(self): ''' + GET_ELEMENT_BY_ATTRIBUTE_TEST_STRING_UPPERCASE = ''' + + ''' + def test_get_element_by_attribute(self): html = self.GET_ELEMENT_BY_CLASS_TEST_STRING @@ -1800,6 +1804,10 @@ def test_get_element_by_attribute(self): self.assertEqual(get_element_by_attribute('itemprop', 'author', html), 'foo') + html = self.GET_ELEMENT_BY_ATTRIBUTE_TEST_STRING_UPPERCASE + + self.assertEqual(get_element_by_attribute('itemprop', 'author', html), 'foo') + def test_get_element_html_by_attribute(self): html = self.GET_ELEMENT_BY_CLASS_TEST_STRING @@ -1858,7 +1866,7 @@ def test_get_elements_text_and_html_by_attribute(self): random text lorem ipsum

this should be returned - this should also be returned + this should also be returned
this should also be returned
@@ -1880,6 +1888,10 @@ def test_get_element_text_and_html_by_tag(self): self.assertEqual( get_element_text_and_html_by_tag('span', html), (self.GET_ELEMENT_BY_TAG_RES_INNERSPAN_TEXT, self.GET_ELEMENT_BY_TAG_RES_INNERSPAN_HTML)) + self.assertEqual( + get_element_text_and_html_by_tag('SPAN', html), + (self.GET_ELEMENT_BY_TAG_RES_INNERSPAN_TEXT, self.GET_ELEMENT_BY_TAG_RES_INNERSPAN_HTML)) + self.assertRaises(compat_HTMLParseError, get_element_text_and_html_by_tag, 'article', html) def test_iri_to_uri(self): diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 4093c238c..f42d8e08c 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -432,10 +432,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'' whole_start = find_or_raise( html, f'<{tag}', compat_HTMLParseError(f'opening {tag} tag not found')) @@ -444,7 +448,7 @@ def find_or_raise(haystack, needle, exc): content_start += whole_start + 1 with HTMLBreakOnClosingTagParser() as parser: parser.feed(html[whole_start:content_start]) - if not parser.tagstack or parser.tagstack[0] != tag: + if not parser.tagstack or parser.tagstack[0] != tag.lower(): raise compat_HTMLParseError(f'parser did not match opening {tag} tag') offset = content_start while offset < len(html):