Navicat工具实现 可以用Navicat连上sqlite数据库,导入spfwssflbm.xml到sqlite3数据库里面再导出表格 代码实现 直接解析gbk编码的xml文件 tree = ET.parse('spfwssflbm.xml') root = tree.getroot() 需要 1、将C:\Program Files (x86)\开票软件\税号.分机号\Bin下的商品服务税收分类编码spfwssflbm.xml文件放到当前终端下,并用记事本打开另存为utf-8格式 2、首行<?xml version="1.0" encoding="gbk"?>中的编码gbk改为utf-8,不然xml.etree.ElementTree无法解析中文报错 spfwssflbm.xml 参考资料 http://blog.appliedinformaticsinc.com/how-to-parse-and-convert-xml-to-csv-using-python/ https://docs.python.org/3/library/xml.etree.elementtree.html https://python3-cookbook.readthedocs.io/zh_CN/latest/c06/p03_parse_simple_xml_data.html 环境 python3.7.2 jupyter notebook、vscode、PyCharm、Thonny上验证通过 excel to dict import pandas as pd my_dic = pd. read_excel ( r 'C: \U sers \D ZL \D esktop \s pfwssflbm.xlsx' , index_col = 0 ) . to_dict ( ) print ( my_dic ) 代码如下 import xml . etree . ElementTree as ET import csv import pandas as pd ...