Created
May 23, 2019 19:29
-
-
Save maik-s/fc8f1c05101a84c3945f4b0a8b6ed874 to your computer and use it in GitHub Desktop.
Simple gist to demonstrate how to use lxml to find elements within an XML string with xpath expressions.
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
#!/bin/python3 | |
from lxml import etree | |
from StringIO import StringIO | |
parser = etree.XMLParser(remove_blank_text=True) | |
f = StringIO('<foo><bar>test</bar></foo>') | |
tree = etree.parse(f, parser) | |
elem = tree.xpath('/foo/bar') | |
print (elem[0].text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment