sportsref/utils.py
def flatten_links(td, _recurse=False):
    """Flattens relative URLs within text of a table cell to IDs and returns
    the result.

    :td: the PyQuery object for the HTML to convert
    :returns: the string with the links flattened to IDs
    """

    # helper function to flatten individual strings/links
    def _flatten_node(c):
        if isinstance(c, basestring):
            return c.strip()
        elif 'href' in c.attrib:
            c_id = rel_url_to_id(c.attrib['href'])
            return c_id if c_id else c.text_content().strip()
        else:
            return flatten_links(pq(c), _recurse=True)

    # if there's no text, just return None
    if td is None or not td.text():
        return '' if _recurse else None

    td.remove('span.note')
    return ''.join(_flatten_node(c) for c in td.contents())
def flatten_links(td, _recurse=False):
    # helper function to flatten individual strings/links
    def _flatten_node(c):
        if isinstance(c, basestring):
            return c.strip()
        elif 'href' in c.attrib:
            c_id = rel_url_to_id(c.attrib['href'])
            return c_id if c_id else c.text_content().strip()
        else:
            return flatten_links(pq(c), _recurse=True)

    # if there's no text, just return None
    if td is None or not td.text():
        return '' if _recurse else None

    td.remove('span.note')
    return ''.join(_flatten_node(c) for c in td.contents())
def flatten_links ( td , _recurse = False ) : # helper function to flatten individual strings/links def _flatten_node ( c ) : if isinstance ( c , basestring ) : return c . strip ( ) elif 'href' in c . attrib : c_id = rel_url_to_id ( c . attrib [ 'href' ] ) return c_id if c_id else c . text_content ( ) . strip ( ) else : return flatten_links ( pq ( c ) , _recurse = True ) # if there's no text, just return None if td is None or not td . text ( ) : return '' if _recurse else None td . remove ( 'span.note' ) return '' . join ( _flatten_node ( c ) for c in td . contents ( ) )
Flattens relative URLs within text of a table cell to IDs and returns
    the result.

    :td: the PyQuery object for the HTML to convert
    :returns: the string with the links flattened to IDs
Flattens relative URLs within text of a table cell to IDs and returns the result .