mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-27 08:58:30 +00:00
Merge c49aa772cc
into 06c1a8cdff
This commit is contained in:
commit
3f5cf9d485
@ -1787,6 +1787,10 @@ def test_get_element_html_by_class(self):
|
|||||||
<div itemprop="author" itemscope>foo</div>
|
<div itemprop="author" itemscope>foo</div>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
GET_ELEMENT_BY_ATTRIBUTE_TEST_STRING_UPPERCASE = '''
|
||||||
|
<DIV itemprop="author" itemscope>foo</DIV>
|
||||||
|
'''
|
||||||
|
|
||||||
def test_get_element_by_attribute(self):
|
def test_get_element_by_attribute(self):
|
||||||
html = self.GET_ELEMENT_BY_CLASS_TEST_STRING
|
html = self.GET_ELEMENT_BY_CLASS_TEST_STRING
|
||||||
|
|
||||||
@ -1798,6 +1802,10 @@ def test_get_element_by_attribute(self):
|
|||||||
|
|
||||||
self.assertEqual(get_element_by_attribute('itemprop', 'author', html), 'foo')
|
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):
|
def test_get_element_html_by_attribute(self):
|
||||||
html = self.GET_ELEMENT_BY_CLASS_TEST_STRING
|
html = self.GET_ELEMENT_BY_CLASS_TEST_STRING
|
||||||
|
|
||||||
@ -1856,7 +1864,7 @@ def test_get_elements_text_and_html_by_attribute(self):
|
|||||||
random text lorem ipsum</p>
|
random text lorem ipsum</p>
|
||||||
<div>
|
<div>
|
||||||
this should be returned
|
this should be returned
|
||||||
<span>this should also be returned</span>
|
<SPAN>this should also be returned</SPAN>
|
||||||
<div>
|
<div>
|
||||||
this should also be returned
|
this should also be returned
|
||||||
</div>
|
</div>
|
||||||
@ -1878,6 +1886,10 @@ def test_get_element_text_and_html_by_tag(self):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
get_element_text_and_html_by_tag('span', html),
|
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.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)
|
self.assertRaises(compat_HTMLParseError, get_element_text_and_html_by_tag, 'article', html)
|
||||||
|
|
||||||
def test_iri_to_uri(self):
|
def test_iri_to_uri(self):
|
||||||
|
@ -432,10 +432,14 @@ def get_element_text_and_html_by_tag(tag, html):
|
|||||||
return its' content (text) and the whole element (html)
|
return its' content (text) and the whole element (html)
|
||||||
"""
|
"""
|
||||||
def find_or_raise(haystack, needle, exc):
|
def find_or_raise(haystack, needle, exc):
|
||||||
try:
|
with contextlib.suppress(ValueError):
|
||||||
return haystack.index(needle)
|
return haystack.index(needle)
|
||||||
except ValueError:
|
|
||||||
raise exc
|
with contextlib.suppress(ValueError):
|
||||||
|
return haystack.index(needle.upper())
|
||||||
|
|
||||||
|
raise exc
|
||||||
|
|
||||||
closing_tag = f'</{tag}>'
|
closing_tag = f'</{tag}>'
|
||||||
whole_start = find_or_raise(
|
whole_start = find_or_raise(
|
||||||
html, f'<{tag}', compat_HTMLParseError(f'opening {tag} tag not found'))
|
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
|
content_start += whole_start + 1
|
||||||
with HTMLBreakOnClosingTagParser() as parser:
|
with HTMLBreakOnClosingTagParser() as parser:
|
||||||
parser.feed(html[whole_start:content_start])
|
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')
|
raise compat_HTMLParseError(f'parser did not match opening {tag} tag')
|
||||||
offset = content_start
|
offset = content_start
|
||||||
while offset < len(html):
|
while offset < len(html):
|
||||||
|
Loading…
Reference in New Issue
Block a user