代码拉取完成,页面将自动刷新
from xml.etree.ElementTree import *
import xmltodict
tree = ElementTree(file='./resources/测试精华(这是标题)1.mscx')
root = tree.getroot()
print(root.tag)
print(root.attrib)
print(type(root))
# for child in root:
# print(child.tag, child.attrib)
for ele in tree.iter():
# if ele.tag == "metaTag":
print(ele.tag, ele.attrib, ele.text)
# print("self." + ele.attrib.get("name") + " = [" + str(ele.attrib) + ", None]")
if __name__ == '__main__':
pass
# with open('./resources/测试精华(这是标题)1.mscx') as f:
# k = f.read()
# print(xml_to_dict(k))
# xmltodict.parse('./resources/测试精华(这是标题)1.mscx')
# with open('./resources/新建 文本文档.txt')as a:
# print(a.read())
with open('./resources/测试精华(这是标题)1.mscx', encoding='utf-8') as fd:
doc = xmltodict.parse(fd.read())
print(doc)
# print(doc['mydocument']['@has']) # == u'an attribute'
# print(doc['mydocument']['and']['many']) # == [u'elements', u'more elements']
# print(doc['mydocument']['plus']['@a']) # == u'complex'
# print(doc['mydocument']['plus']['#text']) # == u'element as well'
with open('./resources/新建 文本文档.txt', 'w', encoding='utf-8') as fd:
fd.write(str(doc))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。