projects
/
youtube-dl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
1721fef
)
[utlis] add extract_attributes for extracting html tags attributes
author
remitamine
<remitamine@gmail.com>
Fri, 11 Sep 2015 03:44:17 +0000
(
04:44
+0100)
committer
remitamine
<remitamine@gmail.com>
Fri, 11 Sep 2015 03:44:17 +0000
(
04:44
+0100)
youtube_dl/utils.py
patch
|
blob
|
history
diff --git
a/youtube_dl/utils.py
b/youtube_dl/utils.py
index 206dd56bcc6da0278543c54f0066df25f50842de..bcebf9cc5cd278a33c4df11c1feecd19d919e23a 100644
(file)
--- a/
youtube_dl/utils.py
+++ b/
youtube_dl/utils.py
@@
-248,6
+248,14
@@
def get_element_by_attribute(attribute, value, html):
return unescapeHTML(res)
+def extract_attributes(attributes_str, attributes_regex=r'(?s)\s*([^\s=]+)\s*=\s*["\']([^"\']+)["\']'):
+ attributes = re.findall(attributes_regex, attributes_str)
+ attributes_dict = {}
+ if attributes:
+ attributes_dict = {attribute_name: attribute_value for (attribute_name, attribute_value) in attributes}
+ return attributes_dict
+
+
def clean_html(html):
"""Clean an HTML snippet into a readable string"""