Getting an empty list as attribute when parsing XML with xml.etree.ElementTree
Question: So I use python 3 to parse an 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>'''
    

I try to get `subjname`, using `xml.etree.ElementTree` this way.

    
    
    >>> import xml.etree.ElementTree  as ET
    >>> doc = ET.fromstring(text)
    >>> print(doc[0][0][7].tag)
    subjname
    >>> print(doc[0][0][7].attrib)
    {}
    

So I always get an empty dict. But I can't find the problem. I thought the
problem is that attributes are Cyrillic, but the same problem occurs when I
try to get the `cmid` attribute

    
    
    >>> doc = ET.fromstring(r.text.encode('utf-8'))
    >>> print(doc[0][0][0].attrib)
    {}
    


Answer: `.attrib` is an empty dictionary in your case since _the tags you show don't
have any attributes at all_. You probably meant to get the
[`.text`](https://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.text)
instead:

    
    
    doc.find("subjname").text
    

