所以我使用python 3来解析XML。
text = '''
<body>
<list>
<item>
<cmid>16934673</cmid>
<day>29.02.2016</day>
<relay>1</relay>
<num>1</num>
<starttime>08:15</starttime>
<endtime>08:55</endtime>
<subjid>81327</subjid>
<subjname>Литературное чтение</subjname>
<subjabbr>Лит.чт.</subjabbr>
<sgid>447683</sgid>
<sgname>Литературное чтение</sgname>
<tid>551817</tid>
<tlastname>Фамилия</tlastname>
<tfirstname>Имя</tfirstname>
<tmidname>Отчество</tmidname>
<roomid>68672</roomid>
<roomname>Филиал 1 кабинет</roomname>
</item>
</list>
</body>'''
我尝试以subjname
方式获取xml.etree.ElementTree
。
>>> import xml.etree.ElementTree as ET
>>> doc = ET.fromstring(text)
>>> print(doc[0][0][7].tag)
subjname
>>> print(doc[0][0][7].attrib)
{}
所以我总是得到一个空头。但我找不到问题。我认为问题是属性是西里尔字母,但当我尝试获取cmid
属性
>>> doc = ET.fromstring(r.text.encode('utf-8'))
>>> print(doc[0][0][0].attrib)
{}