【发布时间】:2011-07-02 14:34:33
【问题描述】:
你好,我有一个编码问题
当我把字符串放到 beautifulsoup 中时,所有的 National char 都丢失了
addr = "http://zjazdowa.com.pl/index.php/aktualne-ceny-warzyw-i-owocow-.html"
content = urllib2.urlopen(addr) .read()
html_pag = BeautifulSoup(content) #<- there i lost all national letters
table_html= html_pag.find("div", id="808")
在我的头文件中:
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
import urllib2, string, re , sys
reload(sys)
sys.setdefaultencoding("utf-8")
【问题讨论】:
-
您发布的代码有效,并保留了所有“国家”字符。
标签: python encoding utf-8 ascii beautifulsoup