Created
September 24, 2011 17:05
-
-
Save netdesign/1239553 to your computer and use it in GitHub Desktop.
python lxml.etree.iterparse
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 lxml.etree as tr | |
| context = tr.iterparse('content.rdf.u8', events=('end',), tag='{http://dmoz.org/rdf/}ExternalPage') | |
| for event, elem in context: | |
| print('%s' % elem[0].text.encode('utf-8')) | |
| print('%s' % elem[1].text.encode('utf-8')) | |
| print(elem.attrib['about']+"\n") | |
| #print('%s\n' % elem[1].text.encode('utf-8')) | |
| elem.clear() | |
| while elem.getprevious() is not None: | |
| del elem.getparent()[0] |
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
| Traceback (most recent call last): | |
| File "parser.py", line 6, in <module> | |
| print('%s' % elem[1].text.encode('utf-8')) | |
| AttributeError: 'NoneType' object has no attribute 'encode' |
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
| <ExternalPage about="http://www.castles99.ukprint.com/Essays/stapleton.html"> | |
| <d:Title>Stapleton Castle, Herefordshire</d:Title> | |
| <d:Description></d:Description> | |
| <topic>Top/Arts/Architecture/Building_Types/Fortifications/Castles/United_Kingdom/England</topic> | |
| </ExternalPage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment