我把美德用于从过去的奥运会中吸引奖牌胜者。 它在一些活动和运动员名称中使用acc子。 我在网上看到了类似的问题,但我说,我是一把新谢拉,在我的法典中难以应用这些问题。
If I print my soup, the accents appear fine. but when I start parsing the soup (and write it to a CSV file) the accented characters become garbled. Louis Perrée becomes Louis Perr√©e
from BeautifulSoup import BeautifulSoup
import urllib2
response = urllib2.urlopen( http://www.databaseolympics.com/sport/sportevent.htm?sp=FEN&enum=130 )
html = response.read()
soup = BeautifulSoup(html)
g = open( fencing_medalists.csv , w" )
t = soup.findAll("table", { class : pt8 })
for table in t:
rows = table.findAll( tr )
for tr in rows:
cols = tr.findAll( td )
for td in cols:
theText=str(td.find(text=True))
#theText=str(td.find(text=True)).encode("utf-8")
if theText!="None":
g.write(theText)
else:
g.write("")
g.write(",")
g.write("
")
许多人感谢你们的帮助。