def parse_html(txt):
    """ reads a string of html and returns a dict/list/tuple presentation"""
pass

def breadth_first_search(graph, start, end):
    """ finds the shortest way from start to end
    You can probably customize start and end to work well with the input you want
    to provide. For implementation details see the link in the text above.
    """
pass

def find_nearest_link(html, name):
    """putting it all together"""
return breadth_first_search(parse_html(html), name, 'link')
Find nearest link with BeautifullSoup (python)