xml读取

import sys
from xml.dom.minidom import parse

def readXML():
domTree = parse("D:\下载\CNBlogs_BlogBackup_131_201711_202004.xml")
rootNode = domTree.documentElement

elements = rootNode.getElementsByTagName("item")
for element in elements:
    title= element.getElementsByTagName("title")[0].childNodes[0].data
    title = str(title).replace("/", "")
    title = str(title).replace("\"", "")
    title = str(title).replace("\'", "")
    desc = element.getElementsByTagName("description")[0].childNodes[0].data
    #desc = desc.replace("\xa0", "")
    fo = open(title+".md", "w",encoding='utf-8')
    fo.write(desc)
    fo.close()

if name == 'main':
readXML()

posted @ 2020-04-26 12:01  abcyrf  阅读(114)  评论(0编辑  收藏  举报