更新时间:2023-11-07 13:44:04
执行(嵌套)迭代需要2个步骤: sec ,然后点击标题。像这样的东西:
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", ""))
有关更多详细信息,请检查 [Python 3.Docs]:xml.etree.ElementTree-ElementTree XML API 。
For more details, check [Python 3.Docs]: xml.etree.ElementTree - The ElementTree XML API.