【发布时间】:2016-10-29 06:53:52
【问题描述】:
我正在尝试使用 BeautifulSoup 和 urllib2 从网站获取一些西班牙语文本。我目前得到这个:¡Hola! ¿Cómo estás?。
我已经尝试应用我在相关线程上看到的不同 unicode 函数,但似乎对我的问题没有任何作用:
# import the main window object (mw) from aqt
from aqt import mw
# import the "show info" tool from utils.py
from aqt.utils import showInfo
# import all of the Qt GUI library
from aqt.qt import *
from BeautifulSoup import BeautifulSoup
import urllib2
wiki = "http://spanishdict.com/translate/hola"
page = urllib2.urlopen(wiki)
soup = BeautifulSoup(page)
dictionarydiv = soup.find("div", { "class" : "dictionary-neodict-example" })
dictionaryspans = dictionarydiv.contents
firstspan = dictionaryspans[0]
firstspantext = firstspan.contents
thetext = firstspantext[0]
thetextstring = str(thetext)
【问题讨论】:
-
print thetextstring看起来不错 -
@FranciscoCouzo 仅适用于 UTF-8 终端。 OP 可能在 Windows 上。
标签: python unicode utf-8 beautifulsoup urllib2