示例: 我有非常相似的内容如下docx文件
Introduction
A. This is text
This is second text
1.1 more complex st
Yes it is
I. Now Roman
我想将输出存储在json数据结构中。上面应该是
输出
{'A': 'This is text', '1': 'This is second text', '1.1': 'more complex st', '2': 'Yes it is', 'I': 'Now Roman'}
我现在的代码是
from docx import Document
document = Document('myDoc.docx')
for para in document.paragraphs:
print para.text
但是这个代码的问题是段落文本不包含段落编号。它只包含段落内容。 例子 对于“A.这是文本”,段落文本只包含“这是文本”,但我想要“A。这是文本”。在
谢谢
首先,使用插件(https://github.com/thepankajsingh/extract-doc-add-ins)将Doc/Word转换为HTML。现在您可以轻松地解析HTML来获得键值对。在
使用python docx模块
像这样读取数据:
一旦你有了数据,你就可以建立你的字典了
相关问题 更多 >
编程相关推荐