我正在嘗試解析 docx 文件。我先解壓縮它,然后嘗試讀取 Document.xml 文件,with open(..)并引發錯誤“'charmap'編解碼器無法解碼位置 7618 中的字節 0x98:字符映射到”。XML 是“UTF-8”編碼:錯誤:我寫了以下代碼: with open(self.tempDir + self.CONFIG['main_xml']) as xml_file:
self.dom_xml = etree.parse(xml_file)我嘗試強制編碼為 UTF-8,但隨后我無法etree.fromstring(..)正確讀取7618 符號(來自錯誤)是:請幫我。如何正確讀取xml文件?謝謝
1 回答

蝴蝶刀刀
TA貢獻1801條經驗 獲得超8個贊
這對您的文件沒有錯誤:
import zipfile
import xml.etree.ElementTree as ET
zipfile.ZipFile('file.docx').extractall()
root = ET.parse('word/document.xml').getroot()
添加回答
舉報
0/150
提交
取消