この問題に関するスレッドがたくさんあることは知っていますが、問題を解決するスレッドを見つけることができませんでした。
文字列を印刷しようとしていますが、印刷すると特殊文字 (æ、ø、å、ö、ü など) が表示されません。これを使用して文字列を印刷すると、次のrepr()
ようになります。
u'Von D\xc3\xbc'
とu'\xc3\x96berg'
Von Dü
これをand に変換する方法を知っている人はいますÖberg
か? これらの文字が無視されないことが重要ですmyStr.encode("ascii", "ignore")
。
編集
これは私が使用するコードです。BeautifulSoup を使用して Web サイトをスクレイピングしています。<td>
テーブル ( ) 内のセル ( ) の内容は<table>
、変数 に入れられますname
。これは、印刷できない特殊文字を含む変数です。
web = urllib2.urlopen(url);
soup = BeautifulSoup(web)
tables = soup.find_all("table")
scene_tables = [2, 3, 6, 7, 10]
scene_index = 0
# Iterate over the <table>s we want to work with
for scene_table in scene_tables:
i = 0
# Iterate over < td> to find time and name
for td in tables[scene_table].find_all("td"):
if i % 2 == 0: # td contains the time
time = remove_whitespace(td.get_text())
else: # td contains the name
name = remove_whitespace(td.get_text()) # This is the variable containing "nonsense"
print "%s: %s" % (time, name,)
i += 1
scene_index += 1