我想用python读取PPTX文件的XML,然后将字符串/数据结构保存到一个变量中。
我还找不到让我用Python做这件事的包。
发布于 2020-09-02 18:04:36
如果我理解正确的话,您可以只使用内置的zipfile模块。
import zipfile
archive = zipfile.ZipFile('<My Powerpoint Name>.pptx', 'r')
xml_file = archive.open('[Content_Types].xml')
text = xml_file.read()
print(text)这将直接在归档文件中打印出[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)https://stackoverflow.com/questions/63702975
复制相似问题