我试着为我的设备写一个解析器。但是我不明白我犯了什么错误,因为我得到了错误:
print(value2['@id'])
TypeError: list indices must be integers or slices, not str
我的代码你可能会看到下面:
import requests
import xmltodict
url = 'http://192.168.1.8:8060/query/apps'
text = requests.get(url).text
#content = """
#<?xml version="1.0" encoding="UTF-8"?>
#<apps>
#<app id="31012" type="menu" #version="2.0.53">Vudu Movie & #TV Store</app>
#</apps>
#"""
text = text.split('\n')
text = text[1:]
text = ''.join(text)
data = xmltodict.parse(text)
data = dict(data)
for key1, value1 in data.items():
for key2, value2 in value1.items():
print(value2['@id'])
print(value2['@type'])
print(value2['#text'])
有人能帮我吗?
1条答案
按热度按时间b1zrtrql1#