欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python解析xml文件實(shí)例分享

 更新時(shí)間:2013年12月04日 14:41:17   作者:  
這篇文章主要介紹了python解析XML文件的方法,大家參考使用吧



復(fù)制代碼 代碼如下:

def get_area_list(self):
        """獲取地域省份和城市名稱字典"""
        page = urllib2.urlopen(self.xml_url).read()
        area_list = {}
        root = ElementTree.fromstring(page)
        #讀取xml格式文本
        for onep in root:
            province =  onep.get('name')
            #父標(biāo)簽中的name數(shù)據(jù)(province中)
            city_list = []
            for onec in onep:
                #子標(biāo)簽中的name數(shù)據(jù)(city中)
                city = onec.get('name')
                city_list.append(city)
            area_list[province] = city_list
            #返回一個(gè)省份與城市關(guān)系的字典,即:{省份名稱:[城市名稱1,城市名稱2,···]}
        return area_list

相關(guān)文章

最新評(píng)論