页面是这个:
http://sports.sina.com.cn/g/premierleague/index.shtml
代码:
# coding: u8
import urllib2
url = "http://sports.sina.com.cn/g/premierleague/index.shtml"
response = urllib2.urlopen(url)
html = response.read()
print html
输出:

编码问题参考了 http://in355hz.iteye.com/blog/1860787 ,感觉基本明白怎么回事儿了,按理说
isinstance(html, str) == True
并且页面的编码确定为 GBK ,那么
html.decode('gbk').encode('utf-8')
就应该解决问题的,可是收到这样的提示:
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 1-2: illegal multibyte sequence
我也试过其它的网站,就新浪会抓到这些鬼东西,这些是 gzip 以后的东西吗?我还有什么没有做,应该怎么办呢?
http://sports.sina.com.cn/g/premierleague/index.shtml
代码:
# coding: u8
import urllib2
url = "http://sports.sina.com.cn/g/premierleague/index.shtml"
response = urllib2.urlopen(url)
html = response.read()
print html
输出:

编码问题参考了 http://in355hz.iteye.com/blog/1860787 ,感觉基本明白怎么回事儿了,按理说
isinstance(html, str) == True
并且页面的编码确定为 GBK ,那么
html.decode('gbk').encode('utf-8')
就应该解决问题的,可是收到这样的提示:
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 1-2: illegal multibyte sequence
我也试过其它的网站,就新浪会抓到这些鬼东西,这些是 gzip 以后的东西吗?我还有什么没有做,应该怎么办呢?