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. ...