#NEWLINE# def traverser( parent , graph , pruning , namedAttrs ) : #NEWLINE# #INDENT# graph = [ ] #NEWLINE# for x in parent : #NEWLINE# #INDENT# if isinstance ( x , bs4 . element . Tag ) : #NEWLINE# #INDENT# my_string = get_name ( x , namedAttrs ) #NEWLINE# graph . append ( Node ( my_string , traverser ( x , graph , pruning , namedAttrs ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not pruning ) : #NEWLINE# #INDENT# return graph #NEWLINE# #UNINDENT# pruned_graph = [ ] #NEWLINE# watcher = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for x in graph : #NEWLINE# #INDENT# blood = '' . join ( x . lineage ( ) ) #NEWLINE# if ( blood not in watcher ) : #NEWLINE# #INDENT# watcher [ blood ] = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# watcher [ blood ] += 1 #NEWLINE# #UNINDENT# #UNINDENT# new_watcher = [ ] #NEWLINE# for x in graph : #NEWLINE# #INDENT# blood = '' . join ( x . lineage ( ) ) #NEWLINE# if ( blood not in new_watcher ) : #NEWLINE# #INDENT# new_watcher . append ( blood ) #NEWLINE# pruned_graph . append ( Node ( ( ( ( x . name + ' (' ) + str ( watcher [ blood ] ) ) + ')' ) , x . children ) ) #NEWLINE# #UNINDENT# #UNINDENT# return pruned_graph