要抓取的网页是gb2312的编码,但是脚本是在Linux下运行,使用utf-8,需要转码。
后来直接用转python的打印方法转换
import urllib
_str = urllib.urlopen(“http://www.xxxxx.com”).read()
get_data = u”%s” % _str.decode(‘gb2312’, ‘ignore’)
get_data就是utf-8格式。
要抓取的网页是gb2312的编码,但是脚本是在Linux下运行,使用utf-8,需要转码。
后来直接用转python的打印方法转换
import urllib
_str = urllib.urlopen(“http://www.xxxxx.com”).read()
get_data = u”%s” % _str.decode(‘gb2312’, ‘ignore’)
get_data就是utf-8格式。