首页 > 编程语言 > 详细

Python 爬虫解码问题解决

时间:2015-07-23 17:54:40      阅读:325      评论:0      收藏:0      [点我收藏+]
import urllib
response = urllib.request.urlopen(‘http://math.sysu.edu.cn/main/default/index.aspx‘)
html = response.read()
html = html.decode(‘utf-8‘)
print(html)

上述代码会出现如下错误:

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd6 in position 396: invalid continuation byte 

问题是解码错误

只需将 html = html.decode(‘utf-8‘) 换成 html = html.decode(‘gbk‘) 即可

版权声明:本文为博主原创文章,未经博主允许不得转载。

Python 爬虫解码问题解决

原文:http://blog.csdn.net/u012675539/article/details/47024309

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!