我使用textract python-pptx来提取效果很好的文件的文本内容。不幸的是我们的客户端还有需要处理的ppt文件,但我们在服务器上没有任何MS Office / Open Office,所以我无法使用comtypes将ppt文件转换为另一种文件类型并从那里开始提取。
非常感谢替代方法的任何建议。
我在Windows 64位计算机上运行Python 3.6。
答案 0 :(得分:0)
在这里转换它们。 https://convertio.co/ppt-pptx/这样您就可以将它们与您的程序一起使用。
答案 1 :(得分:0)
from os.path import isfile, join
import os
import re
from pptx import Presentation
def getPptContent(path):
prs = Presentation(path)
text_runs = []
for slide in prs.slides:
for shape in slide.shapes:
if not shape.has_text_frame:
continue
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
text_runs.append(run.text)
return text_runs
ppt_dir = "ppt_data"
corpus = [str(f) for f in os.listdir(ppt_dir) if not f.startswith('.') and isfile(join(ppt_dir, f))]
for filename in corpus:
Path = ppt_dir + "/" +filename
print(Path)
file_content = getPptContent(Path)
f = open(ppt_dir + "/output/" + filename.split(".")[0] +".txt" ,"w+", encoding="utf-8")
f.write(str(file_content))
f.close()