

def remove_trailing_media_div(self):
    'Punish the *last top level* node in the top_node if it\'s\n        DOM depth is too deep. Many media non-content links are\n        eliminated: "related", "loading gallery", etc\n        '

    def get_depth(node, depth=1):
        'Computes depth of an lxml element via BFS, this would be\n            in parser if it were used anywhere else besides this method\n            '
        children = self.parser.getChildren(node)
        if (not children):
            return depth
        max_depth = 0
        for c in children:
            e_depth = get_depth(c, (depth + 1))
            if (e_depth > max_depth):
                max_depth = e_depth
        return max_depth
    top_level_nodes = self.parser.getChildren(self.get_top_node())
    if (len(top_level_nodes) < 3):
        return
    last_node = top_level_nodes[(- 1)]
    if (get_depth(last_node) >= 2):
        self.parser.remove(last_node)

dataset/ETHPy150Open codelucas/newspaper/newspaper/outputformatters.py OutputFormatter.remove_trailing_media_div/original