Python 从 RTF 文件提取文本内容 - 使用 python-docx 库
可以使用 Python 的 'python-docx' 库中的 'Document' 类来打开 RTF 文件,并提取其中的文本内容。
以下是示例代码:
from docx import Document
# 打开 RTF 文件
doc = Document('example.rtf')
# 提取文本内容
text = ''
for para in doc.paragraphs:
text += para.text
# 输出文本内容
print(text)
注意,'python-docx' 库需要安装。可以使用以下命令进行安装:
pip install python-docx
原文地址: https://www.cveoy.top/t/topic/oLhQ 著作权归作者所有。请勿转载和采集!