Python 使用docx从Word文档提取指向目录的超链接
我已经成功地使用以下代码提取到Word文档中外部文件的所有超链接Python 使用docx从Word文档提取指向目录的超链接,python,ms-word,python-docx,Python,Ms Word,Python Docx,我已经成功地使用以下代码提取到Word文档中外部文件的所有超链接 from docx import Document from docx.opc.constants import RELATIONSHIP_TYPE as RT root_doc = 'TEST.docx' document = Document(root_doc) rels = document.part.rels links= [] for rel in rels: if rels[rel].reltype ==
from docx import Document
from docx.opc.constants import RELATIONSHIP_TYPE as RT
root_doc = 'TEST.docx'
document = Document(root_doc)
rels = document.part.rels
links= []
for rel in rels:
if rels[rel].reltype == RT.HYPERLINK:
url = rels[rel]._target
print('Link:', url)
links.append(rels[rel])
唯一的问题是,它似乎没有抓取指向目录的超链接(即没有链接的显式文件,只是一些文件所在的目录)
有人知道如何扩展/更正此代码以处理目录链接吗
提前谢谢
注意:对于那些试图复制的人,我遇到了python docx的版本问题,为了让docx在我的系统上工作,我需要执行以下任务