zoukankan      html  css  js  c++  java
  • 【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据

    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)
  • 相关阅读:
    直方图均衡
    k-means聚类方法
    核函数
    支持向量机(SVM)
    函数的定义和调用
    ES5新增方法
    继承
    构造函数和原型
    面向对象版tab 栏切换
    ES6中的对象与类
  • 原文地址:https://www.cnblogs.com/wanghong1994/p/12179825.html
Copyright © 2011-2022 走看看