将unicode对象附加到lis时出现问题

2024-04-19 00:17:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正准备从这个xml提要http://www.lnv.fr/xml/ajaccio/calendrier.xml导入 我遇到了一些问题,因为我想提取的一些数据有法国口音标记。你知道吗

url = 'http://www.lnv.fr/xml/ajaccio/calendrier.xml'
r = requests.get(url)
soup = BeautifulSoup(r.content)
matches = soup.findAll('match')

当我这么做的时候

for match in matches:
    print match.equipedomicile.string

它会打印出来,就像他们应该的那样。例如,一支带有重音符号的球队,如Sète就没有问题。你知道吗

但当我这么做的时候

def GetGames():
homeTeamList = []    
for match in matches:
    homeTeam = unicode(match.equipedomicile.text)        
    homeTeamList.append(homeTeam)
return homeTeamList

并调用函数列出带有重音符号的团队不正确。ieSète 现在变成u的\xe8te'


Tags: inhttpurlforwwwmatchxmlfr
1条回答
网友
1楼 · 发布于 2024-04-19 00:17:40

您得到的是unicode字符串的repr版本,在列表的各个元素上使用print,您将得到正确的输出。你知道吗

>>> a = [u'S\xe8te']
>>> a
[u'S\xe8te']
>>> print a[0]
Sète

相关问题 更多 >