# -*- coding: utf-8 -*- import zipfile, re, html, os docx = r"docx/邮件/模板/附件下载_邮件识别/邮件识别.docx" with zipfile.ZipFile(docx) as z: xml = z.read("word/document.xml").decode("utf-8") text = re.sub(r"", "\t", xml) text = re.sub(r"", "\n", text) text = re.sub(r"<[^>]+>", "", text) text = html.unescape(text) text = re.sub(r"\n{3,}", "\n\n", text) out = r"data/logs/mail-recognize-docx.txt" os.makedirs("data/logs", exist_ok=True) open(out, "w", encoding="utf-8").write(text) print(out, "chars", len(text)) print(text[:4000])