Find parent element of a 'title' xml tag containing specific text using Python ElementTree

不想你离开。 提交于 2019-12-02 10:00:57

Do a (nested) iteration in 2 steps: on sec and then on title. Something like:

for sec in parent.iter("sec"):
    for title in sec.iter("title"):
        text = title.text
        if text and "methods" in text.lower():
            print("**title: " + text + " **** sec id: " + sec.get("id", ""))

For more details, check [Python 3]: xml.etree.ElementTree - The ElementTree XML API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!