Sublime Text使用BeautifulSoup解析网页,print时报错UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 35: illegal multibyte sequence

0
import sys
from bs4 import BeautifulSoup
import requests
if __name__ == "__main__":
     target = 'http://www.biqukan.com/1_1094/5403177.html'
     req = requests.get(url = target)
     html = req.text
     bf = BeautifulSoup(html,"lxml")
     texts = bf.find_all('div', class_ = 'showtxt')
     print(texts)
print报错内容如下:
 
Traceback (most recent call last):
  File "E:\Python\py\ca.py", line 22, in <module>
    print(texts)
UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 35: illegal multibyte sequence
[Finished in 0.7s]
 
将Sublime Text的配置修改为其它字符集不报错,但是打印不出来内容,现在配置的是cp936
error.jpg
已邀请:
0

ID王大伟 - 人生苦短,我选Python,转行之路如漫漫长夜,唯有不断学习充电保证不停机。 2018-04-15 回答

这是编码解码问题   用utf-8试试
0

lyw2595050 2018-06-08 回答

用utf-8错误是没有的,但是内容没有出来,使用PyScripter没做配置都是正常的,应该是和Sublime Text工具有关系

要回复问题请先登录注册