def _get_element_type(tag):
    """This function extracts the type of tag specified in tag

    Args:
        tag (str or bytes): Full valid html tag from < to >

    Returns:
        str: type of HTML tag, e.g. div, p, meta, span, td, etc
    """
    # decode tag parameter if its a bytes object
    tag = tag.decode() if isinstance(tag, bytes) else tag

    # clean up any leading or trailing spaces
    tag = tag.strip()

    # check that we open with an <
    if not tag.startswith("<"):
        raise ValueError("Parameter 'tag' does not start with '<'")

    # Start off the type variable after the open bracket
    tag_type = tag[1:]

    # Clean up leading spaces
    tag_type = tag_type.strip()
    tag_type_iterator_copy = tag_type

    # Find the first index of the next space or the closing brace
    cur_index = 0
    for character in tag_type_iterator_copy:
        if character.isspace() or character == ">":
            tag_type = tag_type[:cur_index]
            break
        cur_index += 1

    return tag_type