def tagQuery(tag, tag_name, attrs):
    """Custom tag matcher. Takes into account that tags can
    have several classes."""
    if tag_name and tag_name != tag.name:
        return False
    for key, value in attrs.items():
        tag_attribute_value = tag.attrs.get(key)
        if not tag_attribute_value:
            return False
        if not isinstance(tag_attribute_value, list):
            tag_attribute_value = tag_attribute_value.split()
        if value in tag_attribute_value:
            continue
        return False
    return True
