python解析html页面:如何解码字符?

2024-04-18 15:33:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试解析这样的HTML页面

# coding: utf8
[...]
def search(self, a, b):
    word = self.champ_rech_canal.get_text()
    url_canal = "http://www.canalplus.fr/pid3330-c-recherche.html?rechercherSite=" + mot_canal
    try:
       f = urllib.urlopen(url_canal)
       self.feuille_canal = f.read()
       f.close()
    except: 
       self.champ_rech_canal.set_text("La recherche a échoué")
       pass
    print self.feuille_canal

结果很好,我也有“é”或“ô” 我怎样才能破译它? 已尝试:

self.feuille_canal = self.feuille_canal.decode("utf-8")

结果:

UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 8789: invalid continuation byte

Tags: textselfurldefhtml页面byteutf8