Created
September 12, 2012 16:22
-
-
Save hudsonsferreira/3707842 to your computer and use it in GitHub Desktop.
Script para extrair o body do content.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| from elementtree import ElementTree as etree | |
| def get_text_element(tree): | |
| for i in tree.getiterator(): | |
| if 'text' in i.tag and 'text-' not in i.tag: | |
| return i | |
| def return_the_text(element): | |
| string = etree.tostring(element) | |
| text = re.search('</ns0:annotation>.*</ns1:p>', string).group(0) | |
| text = re.sub('</ns0:annotation>', '', text) | |
| text = re.sub('</ns1:p>', '', text) | |
| return text | |
| tree = etree.parse('content.xml') | |
| print return_the_text(get_text_element(tree)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment