为了账号安全,请及时绑定邮箱和手机立即绑定

尝试直接从 URL 解析 XML

尝试直接从 URL 解析 XML

慕码人2483693 2021-08-11 19:58:52
我在看这个 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
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 187 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号