python - How do I query in ElementTree as in Xpath? -
python - How do I query in ElementTree as in Xpath? -
this sample query might in php:
foreach(steps step) { aret_eles = xpath->query(t_elequery, step) }
now in python:
for step in index steps: aret_eles = ?!?!?!?!!??!?!!??!!
i tried this:
for step in index steps: aret_eles = xpath.query(t_elequery, step)
it didn't work. i've imported elementtree xml.etree.elementtree
, though.
the official page able find on xpath
in elementtree
didn't have documentation or examples.... , know how horribly bad python official's tutorials are. so, i'm looking resource.
if have lxml, high-performance, full-featured version of elementtree, installed can utilize xpath follows:
>>> lxml import etree >>> xml = """<ham><spam>hello!</spam> <spam>goodbye!</spam></ham>""" >>> tree.xpath("//spam/text()") ['hello!', 'goodbye!']
i can recommend lxml python xml needs; it's fast , pythonic.
python xpath elementtree
Comments
Post a Comment