python uses xml

#!/usr/bin/python

import xml.etree.ElementTree as etree

tree = etree.parse(wordbook.xml')
root = tree.getroot()
print len(root)

entries = tree.findall('item')

list = []
for word in entries: 
 w = word.find('word')
 s =  w.text
        list.append(s)

f = file('words.txt', 'w')
CODEC = 'utf-8'
for item in list:
 f.write(item.encode(CODEC))
 f.write('\r\n')

f.close()

posted @ 2018-12-23 19:36  super行者  阅读(132)  评论(0编辑  收藏  举报