【发布时间】:2019-06-04 09:00:16
【问题描述】:
我尝试过使用 python-docx 模块。到目前为止,我已经能够从 word 文件中提取特定段落以及整个文本。
pip install --pre python-docx #to install python-docx
from docx import Document
document = Document('file.docx')
document.paragraphs # to extract paragraphs
document.paragraphs[2].text # gives the text
for par in document.paragraphs: # to extract the whole text
print(par.text)
# I tried the below code to find some specific term
for i in range(0, 50, 1):
if (document.paragraphs[i].text == ('Some-word')):
print document.paragraph
我希望在 word 文件中以突出显示的形式找到特定的单词
【问题讨论】:
-
使用
'Some-word' in document.paragraphs[i].text -
我试过用它。它们中的任何一个都没有输出。
标签: python ms-word docx python-docx word-frequency