title: python - How to extract the text of DOCX hyperlinks?
body: <p>Building on <a href="https://stackoverflow.com/questions/40475757/how-to-extract-the-url-in-hyperlinks-from-a-docx-file-using-python">this solution</a>:</p>
  
  <pre><code>from docx import Document
  from docx.opc.constants import RELATIONSHIP_TYPE as RT
  
  document = Document('test.docx')
  rels = document.part.rels
  
  def iter_hyperlink_rels(rels):
      for rel in rels:
          if rels[rel].reltype == RT.HYPERLINK:
              yield rels[rel]._target      
  
  print(iter_hyperlink_rels(rels)
  </code></pre>
  
  <p>I need to get both the url <strong>and</strong> the text of the hyperlink (e.g. <code>mydomain.com</code> for the url and <code>Go to My Domain</code> for the text)</p>