【python小随笔】python 解析xml数据的新手大坑>>抓取多重标签,遍历各标签的数据
2024-09-05 12:45:09
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)
最新文章
- Less使用心得
- fastcgi与cgi的区别
- JS组件系列——两种bootstrap multiselect组件大比拼
- Robot Motion(imitate)
- MVC 直接把数据库的数据输出到view(太神奇了)
- 金蝶K3 破解版
- Ubuntu下Java环境配置
- careercup-链表 2.1
- 2014年百度之星程序设计大赛 - 资格赛 第二题 Disk Schedule
- jstat undocumented
- cctype学习
- Linux使用ssh公钥实现免批量分发管理服务器
- mysql 正则表达式问号
- E - 改革春风吹满地
- A1107. Social Clusters
- Linux学习之RPM包管理-rpm命令管理(十六)
- 向excel中循环插入值
- TCP/IP 笔记 - ICMPv4和ICMPv6 : Internet控制报文协议
- 走进java
- java开发_";";和null的区别
热门文章
- 使用模块定义AngularJS组件
- PHP导入导出Excel方法小结
- [C#] 如何把void*转换为byte[]
- python编程设计模式之接口类和抽象类
- Chrome 里的请求报错 "; Provisional headers are shown";
- 基于Springboot+Junit+Mockito做单元测试
- 头条面试题-创建一个Event类,并创建on、off、trigger、once方法
- Linux 内核块 urb
- react-native-swiper使用时候的小坑
- iptables总结,开启端口,查看端口占用情况