BeautifulSoup中文乱码问题解决,beautifulsoup乱码,BeautifulSou
BeautifulSoup中文乱码问题解决,beautifulsoup乱码,BeautifulSou
BeautifulSoup在解析utf-8编码的网页时,如果不指定fromEncoding或者将fromEncoding指定为utf-8会出现中文乱码的现象。
解决此问题的方法是将Beautifulsoup构造函数中的fromEncoding参数的值指定为:gb18030
import urllib2from BeautifulSoup import BeautifulSouppage = urllib2.urlopen('http://byrx.net/');soup = BeautifulSoup(page,fromEncoding="gb18030")print soup.originalEncodingprint soup.prettify()
相关内容
- Python采集百度地图数据,python采集地图,百度利用其强大
- python将HSL转换为RGB色彩,pythonhslrgb色彩,将色彩由 HSL 表
- python从无序数组中线性时间找出第K大的数字,python从无
- 使用python脚本获得网站的google pr值和alexa排名,pythonp
- python sqlite3的常规使用,pythonsqlite3常规,python sqlit
- 从python list中删除元素,pythonlist,python的list非
- python cache decorator,pythondecorator,在程序中缓存经常用到
- 让python的json.dumps输出中文,pythonjson.dumps,python的json.
- python使用ctypes调用libcaptcha生成验证码,ctypeslibcaptcha,
- python 中参数用法大全,python参数用法大全,#!/usr/bin/e
评论关闭