...

/

Going Further With lxml

Going Further With lxml

We'll cover the following...

lxml is an open source third-party library that builds on the popular libxml2 parser. It provides a 100% compatible ElementTree api, then extends it with full XPath 1.0 support and a few other niceties. There are installers available for Windows; Linux users should always try to use distribution-specific tools like yum or apt-get to install precompiled binaries from their repositories. Otherwise you’ll need to install lxml manually.

Press + to interact
from lxml import etree #①
tree = etree.parse('feed.xml') #②
root = tree.getroot() #③
print (root.findall('{http://www.w3.org/2005/Atom}entry')) #④
#[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>,
# <Element {http://www.w3.org/2005/Atom}entry at e2b510>,
# <Element {http://www.w3.org/2005/Atom}entry at e2b540>]

① Once imported, lxml provides the same api as the built-in ElementTree library.

parse() function: same as ElementTree. ...