【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据

【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据,第1张

概述xml文档: <GetMatchingProductResult ASIN="B071LF9R6G" status="Success">...&lt
xml文档:<GetMatchingProductResult ASIN="B071LF9R6G" status=Success">...</GetMatchingProductResult><GetMatchingProductResult ASIN=B0714BP3H4B0756FL8R7">...</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)
总结

以上是内存溢出为你收集整理的【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签遍历各标签的数据全部内容,希望文章能够帮你解决【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1190235.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存