Maj*_*Boo 3 python xml powerpoint xml-parsing office365
我想在 python 中读取 PPTX 文件的 XML 并将字符串/数据结构保存到变量中。
我还找不到一个可以让我用 Python 完成此操作的包。
如果我理解正确的话,你可以只使用内置zipfile模块。
import zipfile
archive = zipfile.ZipFile('<My Powerpoint Name>.pptx', 'r')
xml_file = archive.open('[Content_Types].xml')
text = xml_file.read()
print(text)
Run Code Online (Sandbox Code Playgroud)
[Content_Types].xml这将直接从存档内部打印出 xml 文本。
如果你想解析 XML,你可以使用内置xml模块。
import zipfile
import xml.etree.ElementTree as ET
archive = zipfile.ZipFile('<My Powerpoint Name>.pptx', 'r')
xml_file = archive.open('[Content_Types].xml')
text = xml_file.read()
root = ET.fromstring(text)
value_to_find = r'application/vnd.openxmlformats-package.relationships+xml'
for child in root:
if child.attrib['ContentType'] == value_to_find:
print(child.attrib)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
992 次 |
| 最近记录: |