Python从rtf中提取嵌入式文件及其名称

时间:2019-03-21 12:44:16

标签: python-2.7 rtf

我使用的rtfobj是python oletools的一部分,以便从rtf文件中提取嵌入式文件。

    for start_offset, len, _, buff in rtfobj.rtf_iter_objects(rtf_file_path):
        temp = NamedTemporaryFile(delete=False)
        temp.write(buff)
        temp.flush()
        f = OleFileIO(temp.name)
        streams = [x for x in f.listdir() if 'Package' in x or 'CONTENTS' in x]
        stream_buffers = [f.openstream(stream).getvalue() for stream in streams]
        for stream in stream_buffers:
            with open("embedded_file", "wb") as f:
                f.write(stream)

运作良好。嵌入式文件已保存并可以正常打开。

我的问题是如何获取文件名?我知道这些数据存在于某个地方,当我在Office中打开rtf文件时(例如),它向我显示了内部文件及其名称,但我找不到通过python代码获取名称的方法。 >

谢谢

0 个答案:

没有答案
相关问题