def get_section_for_api_title(title, depth=0):
    """
    Traverses the tree upwards from the title node upto 3 levels in search for
    a "section" classed 'div'. If it finds it, returns it.
    """
    for parent in title.parents:
        if parent and parent.has_attr('class') and 'section' in parent['class']:
            return parent
        else:
            if depth == 2:
                return None

            return get_section_for_api_title(parent, depth+1)

    return None