如何在python中打印Ä,Ö,Ü

时间:2016-11-19 11:24:32

标签: python

我在Python中编写一个Crawler,当我抓取德语页面并将其写入txt文件时,它不会写“Ö”,“Ä”或“Ü”,而是\ xD6,\ xF6,...而不是

任何想法如何解决?

        ortschaften = list()
    text_file = open("Output_Brandenburg.txt", "w")
    for x in xrange(1,99):
        ortschaft = str(response.xpath('//*[@id="orte"]/div[1]/ul/li[' + str(x) + ']/a/text()').extract())

        ortschaft.replace("\xD6", "Oe")
        ortschaft.replace("\xF6", "oe")

        ortschaft.replace("\xAE", "Ae")
        ortschaft.replace("\xE4", "ae")

        ortschaft.replace("\xDC", "Ue")
        ortschaft.replace("\xFC", "ue")

        print ortschaft
        text_file.write(ortschaft + "\n")
        if ortschaft is not None:
            ortschaften.append(ortschaft) 
            pass

我的输出示例:

[u'Altreetz']
[u'Am Mellensee']
[u'Angerm\xfcnde']
[u'Annah\xfctte']
[u'Arensdorf']
[u'Bad Belzig']

0 个答案:

没有答案