python获取html编码GB2312中文乱码的问题

来源:互联网 发布:净资产收益率排序软件 编辑:程序博客网 时间:2024/05/29 17:02

GB18030涵盖了GB2312和GBK

# coding:utf-8import sysimport urllib2import refrom BeautifulSoup import BeautifulSoupreload(sys)sys.setdefaultencoding('utf-8')url='http://www.led.hc360.com/'request = urllib2.Request(url)response = urllib2.urlopen(request,data=None,timeout=30)htmlpage = response.read()soup = BeautifulSoup(htmlpage,fromEncoding="GB18030")  #重点使用fromEncoding="GB18030"a_title = soup.find("title")print a_title


0 0
原创粉丝点击