我在python中构建了一个文档检索引擎,它返回按用户提交的查询的相关性排列的文档。我有一个包含PowerPoint文件的文档集合。对于PPT,在结果页面上,我想向用户展示前几个幻灯片标题,以给他/她更清晰的图片(有点像我们在Google搜索中看到的)。python-pptx从幻灯片标题中提取文本
所以基本上,我想从使用python的PPT文件的幻灯片标题中提取文本。我正在使用python-pptx包。目前我的实现看起来是这样的
from pptx import Presentation
prs = Presentation(filepath) # load the ppt
slide_titles = [] # container foe slide titles
for slide in prs.slides: # iterate over each slide
title_shape = slide.shapes[0] # consider the zeroth indexed shape as the title
if title_shape.has_text_frame: # is this shape has textframe attribute true then
# check if the slide title already exists in the slide_title container
if title_shape.text.strip(""" [email protected]#$%^&*)(_-+=}{][:;<,>.?"'/<,""")+ '. ' not in slide_titles:
slide_titles.append(title_shape.text.strip(""" [email protected]#$%^&*)(_-+=}{][:;<,>.?"'/<,""")+ '. ')
但你可以看到我假设每张幻灯片上零索引的形状是幻灯片标题,这显然不是这种情况每次。任何想法如何实现这一目标?
在此先感谢。