def clean_astext(node):
 node = node.deepcopy()
 for img in node.traverse(nodes.image):
  img['alt'] = ''
 for raw in node.traverse(nodes.raw):
  raw.parent.remove(raw)
 return node.astext()

def clean_astext ( node ) : node = node . deepcopy ( ) for img in node . traverse ( nodes . image ) : img [ 'alt' ] = '' for raw in node . traverse ( nodes . raw ) : raw . parent . remove ( raw ) return node . astext ( )
like node .