I am trying to make a wrapper function for the existing itertags one here: https://github.com/streamlink/streamlink/blob/master/src/streamlink/plugin/api/utils.py#L16
Currently i have this:
def itertags_wrapper(html, tag, attrs=None, ret=False):
try:
result = list(itertags(html, tag))
if isinstance(attrs, dict):
attrs = list(iteritems(attrs))
result = [i for i in result if any([a for a in attrs if a in list(iteritems(i.attributes))])]
if ret:
# noinspection PyTypeChecker
result = [i.attributes[ret] for i in result if ret in i.attributes]
except Exception:
result = []
return result
Now it returns the tags containing the exact same key-value pair as in attrs, but HOW do I have the value of the pair in a regex pattern and broaden possible results?
P.S. iteritems is passed through a "compat" module first to work on both python 2 & 3.