python开发文档解析,使用python解析* .nfo文件

I try to parse a nfo file and print in a html code style (a table).

I tried with xml.etree but i get only 2 elements: Metadata and Category.

This is how a .nfo looks like:

8.0

12/02/15 10:45:25

My code looks like:

tree = ET.parse(File)

root = tree.getroot()

for element in root.findall('Category'):

value = element.find('Data')

print element.attrib

But only print Category element, my question is how i can get values from Data?

Thanks!

解决方案

I'm guessing you might be looking to parse through the .nfo output from MSINFO32. The below code was what I found to be the most straightforward way to parse through the entire file, and come out with usable objects.

for element in root.iter('Data'):

out = []

for n in range(len(element)):

out.append('{0}'.format(element[n].text))

print(out)

The output looks like:

['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']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值