我知道有很多关于这个问题的线索,但我没有找到一个解决我的问题。
我试图打印一个字符串,但打印时它不显示特殊字符(例如æ,ø,å,è和è)。当我使用repr()打印字符串时,得到的是:
u'Von D\xc3\xbc'和u'\xc3\x96berg'
有人知道我如何把它转换成Von Dü和Öberg?对我来说,重要的是不能忽略这些字符,例如myStr.encode("ascii", "ignore")。
编辑
这是我使用的代码。我用美女组刮网站。表(
soup = BeautifulSoup(web)
tables = soup.find_all("table")
scene_tables = [2, 3, 6, 7, 10]
scene_index = 0
# Iterate over the
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