xml文檔: <GetMatchingProductResult ASIN="B071LF9R6G" status="Success">...</GetMatchingProductResult> <GetMatchingProductResult ASIN="B0714BP3H4" status="Success">...</GetMatchingProductResult> <GetMatchingProductResult ASIN="B0756FL8R7" status="Success">...</GetMatchingProductResult> <ResponseMetadata> # 使用minidom解析器打開XML文檔 DOMTree = xml.dom.minidom.parse("./test.xml") collection = DOMTree.documentElement # collection是針對整個文件的文檔,GetMatchingProductResults 獲取的是三個名字相同的標簽,不同標簽的數據對象 GetMatchingProductResults = collection.getElementsByTagName('GetMatchingProductResult') # GetMatching 是針對每個標簽對象GetMatching作為xml對象進行對應取值 for GetMatching in GetMatchingProductResults: asin = GetMatching.getElementsByTagName('ASIN')[0].childNodes[0].data print(asin)