我在看这个 XML:https://data.cityofnewyork.us/api/views/25th-nujf/rows.xml我以为我可以使用下面的代码从列表中解析出 'ethcty' 和 'cnt' 项目,但实际上我什么也没得到。import xml.etree.ElementTree as ETtree = ET.parse('https://data.cityofnewyork.us/api/views/25th-nujf/rows.xml')root = tree.getroot()for child in root: print(child.tag, child.attrib)for _id in root.findall('_id'): rank = _id.find('ethcty').text name = _id.get('cnt') print(name, rank)我正在关注以下 URL 中的示例。https://docs.python.org/3.4/library/xml.etree.elementtree.html
添加回答
举报
0/150
提交
取消