X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=3498697b60d70c45d4041f80f59945aefeb9e035;hb=84c237fb8a2afa06fd3c36f7da9517682e63480e;hp=36d5b6c0f244c49526f9f6d2923ae9f40f1965ee;hpb=ab49d7a9fae08763de549f85ba138b22f9122a99;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 36d5b6c0f..3498697b6 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -310,9 +310,17 @@ def get_element_by_id(id, html): return get_element_by_attribute('id', id, html) -def get_element_by_attribute(attribute, value, html): +def get_element_by_class(class_name, html): + return get_element_by_attribute( + 'class', r'[^\'"]*\b%s\b[^\'"]*' % re.escape(class_name), + html, escape_value=False) + + +def get_element_by_attribute(attribute, value, html, escape_value=True): """Return the content of the tag with the specified attribute in the passed HTML document""" + value = re.escape(value) if escape_value else value + m = re.search(r'''(?xs) <([a-zA-Z0-9:._-]+) (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'))*? @@ -321,7 +329,7 @@ def get_element_by_attribute(attribute, value, html): \s*> (?P.*?) - ''' % (re.escape(attribute), re.escape(value)), html) + ''' % (re.escape(attribute), value), html) if not m: return None