从网站获取xml(带有Cyillic符号)后,我使用此代码将其解析为字典
from google.appengine.api import urlfetch
import xml.etree.ElementTree as ET
def get_class_list():
url = 'http://samplehtml.com'
result = urlfetch.fetch(url=url, method = urlfetch.POST)
root = ET.fromstring(result.content)
class_list = []
for child in root[0]:
class_voc = {}
class_voc['classid'] = child.find('classid').text
class_voc['classname'] = child.find('classname').text.encode("utf-8")
class_list.append(class_voc)
return class_list
我将其打印到网页(我使用谷歌应用引擎)并获得此
[{'classid': '75242', 'classname': '1\xc3\xa0'},
{'classid': '75244', 'classname': '1\xc3\xa1'},
{'classid': '75246', 'classname': '1\xc3\xa2'},
{'classid': '75243', 'classname': '2\xc3\xa0'}]
我尝试将其编码为utf-8,但没有结果。如何解码它以获得常规字母?
好的,问题是app引擎不支持这个函数unicode('8в','latin1')
我可以用来比较我需要比较的一些值,因为我可以访问chars 'classname': u'1\xe0'
的unicode表示或者像字母1á
这样的阿拉伯语。所以我需要比较值并将它们写入网页。