| 1234567891011121314151617 |
- # -*- coding: utf-8 -*-
- import zipfile, re, json, sys, io
- sys.stdout.reconfigure(encoding="utf-8")
- p = r"C:\Users\aroun\Desktop\在线考试系统\在线考试系统技术文案(方案B).docx"
- z = zipfile.ZipFile(p)
- xml = z.read("word/document.xml").decode("utf-8")
- paras = re.findall(r"<w:p[ >].*?</w:p>", xml, re.S)
- out = []
- for pa in paras:
- texts = re.findall(r"<w:t[^>]*>(.*?)</w:t>", pa, re.S)
- t = "".join(texts)
- t = t.replace("&", "&").replace("<", "<").replace(">", ">").replace(""", '"')
- m = re.search(r'<w:pStyle w:val="([^"]+)"', pa)
- out.append({"style": m.group(1) if m else "", "text": t})
- with open(r"C:\Users\aroun\Desktop\在线考试系统\_paras.json", "w", encoding="utf-8") as f:
- json.dump(out, f, ensure_ascii=False, indent=0)
- print("paras", len(out))
|