实现方法:通过解压OFD格式文件,得到里面的OFD.xml文件,在通过解析xml文件获取到发票相关信息
from xml.dom.minidom import parse
def get_info(io):
"""
:param : io :解压后OFD.xml的文件路径
:return : ofd_info,字典形式的发票信息
"""
tree = parse(io)
element = tree.documentElement
nodes = element.getElementsByTagName(‘ofd:CustomDatas‘)
ofd_info = {}
for i in range(len(nodes)):
sun_node = nodes[i].childNodes
for j in range(len(sun_node)):
name = sun_node[j].getAttribute(‘Name‘)
value = sun_node[j].firstChild.data
ofd_info[name] =value
return ofd_info
原文:https://www.cnblogs.com/rongge95500/p/14324198.html