我正在尝试从 word 文档中提取一个特定的表格,该表格紧跟在 .docx 文件中的标题“缩写列表”之后,以及紧随标题“图形研究”之后的图像。我已经能够使用 python-docx 代码提取标题,但是如何使用标题或它们的位置来解析文档以检索图像和表格if re.match("Graphical", img.previous_sibling.text)。在我用来搜索我的图像的美丽汤中。我的 python docx 代码是:
from docx import *
document = Document('data/p21.docx')
document.save('test-new.docx')
for content in document.paragraphs:
if content.style.name=='Heading 1' or content.style.name=='Heading 2' or content.style.name=='Heading 3':
print (content.text)