title: Extract a specific table and image from .docx file using python
body: <p>I am trying to extract a specific table from word document which falls right after the heading &quot;List Of Abbreviations &quot; and an image that is right after a heading &quot;Graphical Study&quot; in a .docx file . I have been able to extract the headers using python-docx code but how do I parse the document using the headers or their position to retrieve the image and the table.In beautiful soup I am using <code>if re.match(&quot;Graphical&quot;, img.previous_sibling.text)</code> to search for my image . My python docx code is :</p>
  <pre><code>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)
  </code></pre>