Skip to content

Instantly share code, notes, and snippets.

@zlalanne
Created December 10, 2013 18:58
Show Gist options
  • Save zlalanne/7896096 to your computer and use it in GitHub Desktop.
Save zlalanne/7896096 to your computer and use it in GitHub Desktop.
Get the text of a node and all child nodes into a string
def get_node_text(root):
text = ""
if root.text:
text = root.text.strip()
for child in root:
text += get_node_text(child)
if root.tail:
text += root.tail.strip()
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment