下面是 XML 文件:<Schedule xmlns="http://xmlns.xyz.com/fal/downtimeschedule/V1.0"> <Downtime end="20181020000" id="10001197610_20181027000_201810000" mode="cold" start="20181020000"/> <PODS> <POD DC="US - Washing" deferUpgrade="true" name="ABCD" patching="Production" EndTime="20181028040000"> <CR id="12345"/> <CR id="12346"/> <CR id="123"/> </POD> <POD DC="US - Washing" deferUpgrade="true" name="ABCD-TEST" patching="Production" EndTime="20181028040000"> <CR id="12345"/> <CR id="12346"/> <CR id="123"/> </POD> </PODS>我想在帶有列的 csv 文件中提供輸出1> POD(name)2> POD(DC)3> POD(deferUpgrade)有人可以在這里幫忙。是否可以使用庫 xml.etree.ElementTree,因為我在生產環(huán)境中有這個。下面是代碼。#!/usr/bin/pythonimport osimport pandas as pdimport requestsimport xml.etree.ElementTree as ETtree = ET.parse('schedule.xml')root = tree.getroot()print rootprint root.findall('PODS')for pods in root.iter('Schedule'): for pod in pods.iter('POD'): print pod.get('name')輸出:<Element '{http://xmlns.oracle.com/falcm/flo/downtimeschedule/V1.0}Schedule' at 0x2ae6ed0>[]
添加回答
舉報
0/150
提交
取消