Python2.7编码问题解决办法
2018-02-23 15:32
302 查看
①抓数据前先看html页面的字符集 utf-8/gbk/gb2312
②如果是utf8 在cmd下看会乱码 但是不影响逻辑判断和插入数据库
如果requests请求的话 :
r=requests.get(urls)
解析utf8字符集
c=pq(r.content.decode('utf8',"ignore"))
设置编码utf8
no_search=no_search.encode("utf8")
②如果是utf8 在cmd下看会乱码 但是不影响逻辑判断和插入数据库
如果requests请求的话 :
r=requests.get(urls)
解析utf8字符集
c=pq(r.content.decode('utf8',"ignore"))
设置编码utf8
no_search=no_search.encode("utf8")
③如果是gbk/gb2312的话 r=requests.get(final_url) 解析gbk字符集 d=pq(r.content.decode('gbk',"ignore")) 编码utf8 xx=xx.encode('utf8')注意如果还是乱码的话 在decode解析utf8就行
相关文章推荐
- Ubuntu16.04下在Python2.7安装OpenCV3.2.0出现的问题与解决办法
- 解决Python2.7画三维图像遇到的编码问题
- python2.7 的中文编码处理,解决UnicodeEncodeError: 'ascii' codec can't encode character 问题
- Python2.7编码问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position...解决方法
- python2.7的编码问题与解决方法
- Python3学习之字符编码问题解决办法详解
- 关于Python2.7得到结果乱码的问题解决办法
- python2.7解决中文编码问题
- 使用VS2013编写Python程序时出现编码问题的解决办法
- 全网最详细的跑python2.7时出现from mysql import connector ImportError: No module named mysql的问题解决办法(图文详解)
- 【python学习】编码时写路径使用后斜杠导致的unicode error问题解决办法
- python2.7的编码问题与解决方法
- 解决Python 2.7不能正常使用pip install的问题
- 各种编码问题产生原因以及解决办法---------响应编码,请求编码,URL编码
- Non-ASCII character python文件中有中文编码出错 解决办法
- 【python】logging日志模块写入中文编码错误解决办法
- python问题Non-ASCII character '\xe5' in file Apriori.py on line 1, but no encoding declared 解决办法
- Python 2.7 解决写入文件的中文乱码问题
- python3.2打开utf8的txt文件时BOM问题的解决办法
- python写入csv文件中文乱码问题解决办法