Python 解析XML

Python 解析XML


URL_to_start
http://baike.baidu.com/item/python



count
10



run_time
-1



Thread_count
1



URL_re
*

解析

import xml.dom.minidom

class ReadConf:
def read(self):
# 打开xml文档
dom = xml.dom.minidom.parse('conf.xml')

得到文档元素对象

root = dom.documentElement

conf_nodes = root.getElementsByTagName('conf')
conf_dict = {}

for conf_node in conf_nodes:
conf_dict[conf_node.getElementsByTagName('name')[0].firstChild.data] =
conf_node.getElementsByTagName('value')[
0].firstChild.data

return conf_dict

posted @ 2017-08-12 14:25  岑忠满  阅读(1175)  评论(0)    收藏  举报