From: Yen Chi Hsuan Date: Wed, 5 Jul 2017 15:23:35 +0000 (+0800) Subject: [utils] Support attributes with no values in get_elements_by_attribute() X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=609ff8ca19f1c4c168a81121074b91cc0f0d4c47;p=youtube-dl [utils] Support attributes with no values in get_elements_by_attribute() --- diff --git a/test/test_utils.py b/test/test_utils.py index 2b93b3604..30738e7cf 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1228,6 +1228,12 @@ part 3 self.assertEqual(get_element_by_attribute('class', 'foo', html), None) self.assertEqual(get_element_by_attribute('class', 'no-such-foo', html), None) + html = ''' + + ''' + + self.assertEqual(get_element_by_attribute('itemprop', 'author', html), 'foo') + def test_get_elements_by_class(self): html = ''' nicealso nice diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 39860e9d1..fdf5e29e7 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.*?)