A feature-rich command-line audio/video downloader
[utils] Support attributes with no values in get_elements_by_attribute()
Yen Chi Hsuan609ff8ca19f1
diff --git a/test/test_utils.py b/test/test_utils.pyindex 2b93b36047..30738e7cf4 100644--- a/test/test_utils.py+++ b/test/test_utils.py@@ -1228,6 +1228,12 @@ part 3</font></u>self.assertEqual(get_element_by_attribute('class', 'foo', html), None)self.assertEqual(get_element_by_attribute('class', 'no-such-foo', html), None)+ html = '''+ <div itemprop="author" itemscope>foo</div>+ '''++ self.assertEqual(get_element_by_attribute('itemprop', 'author', html), 'foo')+def test_get_elements_by_class(self):html = '''<span class="foo bar">nice</span><span class="foo bar">also nice</span>diff --git a/youtube_dl/utils.py b/youtube_dl/utils.pyindex 39860e9d15..fdf5e29e7d 100644--- a/youtube_dl/utils.py+++ b/youtube_dl/utils.py@@ -365,9 +365,9 @@ def get_elements_by_attribute(attribute, value, html, escape_value=True):retlist = []for m in re.finditer(r'''(?xs)<([a-zA-Z0-9:._-]+)- (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'))*?+ (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'|))*?\s+%s=['"]?%s['"]?- (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'))*?+ (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'|))*?\s*>(?P<content>.*?)</\1>