python抓取简单爬虫时,如果抓取的网页爬虫数据里面,有不能够utf-8编码的(例如html里面的简体中文),
data=data.decode('UTF-8')
print(data)
报错'gbk' codec can't encode character '\xXX' in position XX
解决办法:修改为
data=data.decode('GBK','ignore')
print(data)
学习文档:http://python.jobbole.com/77821/ http://www.cnblogs.com/sysu-blackbear/p/3629770.html http://www.cnblogs.com/abelsu/p/5105542.html
官方文档:https://docs.python.org/3/library/urllib.html