<commit_before>from bs4 import Tag as bs4Tag


## function to check if an element is a Tag or not.
def is_tag(el):
    return isinstance(el,bs4Tag)<commit_msg>add get_attr<commit_after>from bs4 import Tag as bs4Tag


## function to check if an element is a Tag or not.
def is_tag(el):
    return isinstance(el,bs4Tag)

def get_attr(el, attr, check_name=None ):
    """returns the attribute of an element if it exists and is not empty else returns None. Optional kwarg 'check_name' (as a list of strings or single string) to check element type by name
    """
    if check_name is None:
        attr_value = el.get(attr, None)
    elif el.name in check_name:
        attr_value = el.get(attr, None)
    else:
        attr_value = None

    if isinstance(attr_value, str) or isinstance(attr_value, unicode):
        if attr_value.strip() == "":
            attr_value = None

    return attr_value
{'fraction_non_alphanumeric': 0.08044692737430167, 'fraction_numerical': 0.0067039106145251395, 'mean_word_length': 3.2264150943396226, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1508170', 'n_tokens_mistral': 283, 'n_tokens_neox': 272, 'n_words': 108}