我尝试解析 nfo 文件并以 html 代码样式(表格)打印。
我尝试使用 xml.etree
但我只得到 2 个元素:Metadata
和 Category
。
.nfo 如下所示:
<?xml version="1.0"?>
<MsInfo>
<Metadata>
<Version>8.0</Version>
<CreationUTC>12/02/15 10:45:25</CreationUTC>
</Metadata>
<Category name="System Summary">
<Data>
<Item><![CDATA[OS Name]]></Item>
<Value><![CDATA[Microsoft Windows 8.1 Pro]]></Value>
</Data>
</Category>
</MsInfo>
我的代码如下:
tree = ET.parse(File)
root = tree.getroot()
for element in root.findall('Category'):
value = element.find('Data')
print element.attrib
但只打印类别元素
,我的问题是如何从数据
获取值?
谢谢!
最佳答案
我猜您可能希望解析 MSINFO32 的 .nfo 输出。我发现下面的代码是解析整个文件并得出可用对象的最直接方法。
for element in root.iter('Data'):
out = []
for n in range(len(element)):
out.append('{0}'.format(element[n].text))
print(out)
输出如下:
['OS Name', 'Microsoft Windows 10 Enterprise Evaluation']
['Version', '10.0.15063 Build 15063']
['Other OS Description ', 'Not Available']
['OS Manufacturer', 'Microsoft Corporation']
['System Name', 'WIN10BLANK']
['System Manufacturer', 'Microsoft Corporation']
['System Model', 'Virtual Machine']
['System Type', 'x64-based PC']
['System SKU', 'Unsupported']
关于python - 使用 python 解析 *.nfo 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34070729/