我正在尝试解析以下XML数据以获取所有Key
文件。
这是xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ListBucketResult></ListBucketResult>
xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>icos-s3-grs-sap-pdc-test01</Name>
<Prefix></Prefix>
<Marker></Marker>
<MaxKeys>1000</MaxKeys>
<Delimiter></Delimiter>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>textfile.txt</Key>
<LastModified>2019-07-18T14:18:33.099Z</LastModified>
<ETag>"0b26e313ed4a7ca6904b0e9369e5b957"</ETag>
<Size>19</Size>
<Owner>
<ID>c9e8058f-1d52-7722-11be-f3cab9d2ec50</ID>
<DisplayName>grs-sap</DisplayName>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
这是我正在使用的Python代码:
root = ET.fromstring(xmlstring)
for type_tag in root.findall('Contents/Key'):
value = type_tag.get
print(value)`