【发布时间】:2020-11-05 10:08:12
【问题描述】:
我正在尝试从 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)
【问题讨论】:
标签: python docx python-docx