- python-docx
python-docx是一个用于创建和更新Microsoft Word(.docx)文件的Python库,不支持doc类型的word。
使用命令pip install python-docx安装,具体文档API地址https://python-docx.readthedocs.io/en/latest/index.html
输出文档内容:
#!/usr/bin/python
#解析word,只支持docx结尾的word
from docx import Document
path = 'D:\\test.docx'
document = Document(path)
sections = document.sections
for content in document.paragraphs:
print(content.text)