【发布时间】:2020-06-14 21:53:05
【问题描述】:
当使用 xpath 方法时,我如何获得属性 ID 的值(在下面的示例中应该是“DEF”),它是我的 XPath 结果的子项?
from lxml import etree
from io import StringIO
f = StringIO('<root><row id="DEF">ABC</row></root>')
doc = etree.parse(f)
for c in doc.xpath("/root/row"):
print (c.tag)
#print (c.attribute('id').value)
print (c.value) #shows ABC
【问题讨论】:
标签: python-3.x lxml