|
|
@ -310,9 +310,17 @@ def get_element_by_id(id, html):
|
|
|
|
return get_element_by_attribute('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"""
|
|
|
|
"""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)
|
|
|
|
m = re.search(r'''(?xs)
|
|
|
|
<([a-zA-Z0-9:._-]+)
|
|
|
|
<([a-zA-Z0-9:._-]+)
|
|
|
|
(?:\s+[a-zA-Z0-9:._-]+(?:=[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*>
|
|
|
|
\s*>
|
|
|
|
(?P<content>.*?)
|
|
|
|
(?P<content>.*?)
|
|
|
|
</\1>
|
|
|
|
</\1>
|
|
|
|
''' % (re.escape(attribute), re.escape(value)), html)
|
|
|
|
''' % (re.escape(attribute), value), html)
|
|
|
|
|
|
|
|
|
|
|
|
if not m:
|
|
|
|
if not m:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|