如何在python中打印Ä,Ü

2024-09-30 01:27:37 发布

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

我用Python编写一个爬虫程序,当我抓取德语页面并将其写入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

我的输出例如:

^{pr2}$

Tags: 文件text程序txt页面爬虫replacelist

热门问题