0
私はPython 2.7を使用していますが、 "ä"のような文字を "ae"に変換するときに問題があります。Pythonの文字列をユニコードで符号化する
私が使用してWebページのコンテンツを検索しています:
req = urllib2.Request(url + str(questionID))
response = urllib2.urlopen(req)
data = response.read()
その後私はいくつかの抽出のものをやっているし、私の問題があります。
extractedStr = pageContent[start:end] // this string contains the "ä" !
extractedStr = extractedStr.decode("utf8") // here I get the error, tried it with encode aswell
extractedStr = extractedStr.replace(u"ä", "ae")
- > 'UTF8' コーデックは位置13でバイト0xe4をデコードすることはできません:無効な継続バイト
しかし:私の簡単な試験が正常に動作している...:
someStr = "geräusch"
someStr = someStr.decode("utf8")
someStr = someStr.replace(u"ä", "ae")
私は感覚を持っている、それは何かと.Decode()関数を使用しようとするときに何かを持っている...私はいくつかの位置で成功しませんでした:(
'.decode(" latin-1 ")' –
は今、うまく動作します。 –
データはラテン1でエンコードされているので、charsetはcontent-typeのヘッダーにある必要があります。 –