码迷,mamicode.com
首页 > 编程语言 > 详细

python处理xml实例

时间:2018-10-13 14:42:44      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:file   dir   parse   bin   tor   port   []   read   os.path   

!/usr/bin/env python

-- coding: utf-8 --

"""
Author = zyh
FileName = read_xml_1.py
Time = 18-9-26 下午5:19
"""

from xml.etree import ElementTree
import os

path = (‘/home/zyh/Desktop/xml17‘)
xml_file_list = os.listdir(path)
print(xml_file_list)
read_list = []
with open(‘./riskCar_pic.txt‘, ‘r‘, encoding=‘utf-8‘) as file:
for line in file:
read_list = line.strip()
for xml in xml_file_list:
full_path = os.path.join(path, xml)
print(full_path)
root = ElementTree.parse(full_path)
# print(root)
name_node = root.getiterator(‘name‘)
# print(len(name_node))
for node in name_node:
print(node.text)
if node.text == ‘riskCar‘:
if xml not in read_list:
with open(‘./riskCar_pic.txt‘, ‘a‘, encoding=‘utf-8‘) as f:
f.write(xml + ‘\n‘)

file.close()

python处理xml实例

标签:file   dir   parse   bin   tor   port   []   read   os.path   

原文地址:https://www.cnblogs.com/myblog1993/p/9782735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!