python 内部使用unicode编码
来源:互联网 发布:数据库中的索引是什么 编辑:程序博客网 时间:2024/05/21 13:39
<?phpclass TestAction extends Action { public function index(){#$this->show('Hello world'); $name='怠忽待会';echo $name;#$this->assign('data',$name);#$this->display(); }# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibimport reimport requestss=requests.session()print s.headersurl = "http://127.0.0.1/DEVOPS/index.php/Test/index"headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',}r = s.get(url,headers=headers)r=r.contentprint rprint type(r)print rprint len(r)返回的是utf8字符串,C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a19.py{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}怠忽待会<type 'str'>怠忽待会12把utf8 字符串,转换为unicoder = s.get(url,headers=headers)r=r.contentprint rprint type(r)print rprint len(r)r=r.decode('utf-8')print rprint type(r)print len(r)C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a19.py{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}怠忽待会<type 'str'>怠忽待会12怠忽待会<type 'unicode'>4在cmd运行:# !/usr/bin/env python# -*- coding: utf-8 -*-import urllib2import urllibimport cookielibimport jsonimport httplibimport reimport requestss=requests.session()print s.headersurl = "http://127.0.0.1/DEVOPS/index.php/Test/index"headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',}r = s.get(url,headers=headers)r=r.contentprint rprint type(r)print rprint len(r)C:\Users\TLCB\Desktop\python\Python 高级编程\4>python test.py{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}鎬犲拷寰呬細<type 'str'>鎬犲拷寰呬細12C:\Users\TLCB\Desktop\python\Python 高级编程\4>此时返回的是utf8,乱码,需要把utf8转为gbk-------------------------------------------------------------------------------r = s.get(url,headers=headers)r=r.contentprint rprint type(r)print rprint len(r)r=r.decode('utf-8').encode('gbk')print rprint type(r)print len(r)C:\Users\TLCB\Desktop\python\Python 高级编程\4>python test.py{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}鎬犲拷寰呬細<type 'str'>鎬犲拷寰呬細12怠忽待会<type 'str'>8或者 把utf8转为unicoder = s.get(url,headers=headers)r=r.contentprint rprint type(r)print rprint len(r)r=r.decode('utf-8')print rprint type(r)print len(r)C:\Users\TLCB\Desktop\python\Python 高级编程\4>python test.py{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}鎬犲拷寰呬細<type 'str'>鎬犲拷寰呬細12怠忽待会<type 'unicode'>4C:\Users\TLCB\Desktop\python\Python 高级编程\4>
阅读全文
0 0
- python 内部使用unicode编码
- python中的unicode编码
- python 学习~unicode 编码
- Python编码和Unicode
- Python编码和Unicode
- python 的unicode编码
- Python编码和Unicode
- python unicode编码转换
- 【Python】Python编码和Unicode
- Skin++ 使用unicode编码
- 使用 Unicode 编码
- 使用 Unicode 编码
- python 编码unicode 和 str
- Python 编码 Unicode utf-8
- python unicode-escape编码问题
- python学习之unicode编码
- 使用python将用ASCII表示的16进制unicode编码的ASCII字符串转换为unicode字符串
- [Python学习]Unicode及编码处理心得
- windows下进入linux出现乱码的解决方式
- android style 使用
- 【SSH】Spring学习(一)
- Android 时间倒计时
- java String类原理浅析
- python 内部使用unicode编码
- CentOS 7 下 修改Mysql 5.7datadir的位置,无法启动的问题解决
- 模拟远程温度监控系统(包含程序)
- C#学习总结(1)——与java的几个区别
- 数据结构实验5(从文件中读取数据)
- C语言中位运算异或“∧”的作用
- mt6750 battery_common.c阅读笔记1
- 300. Longest Increasing Subsequence
- LoRa关键参数 1、扩频因子(SF) 2、编码率(CR) 3、信号带宽(BW) 4、LoRa信号带宽BW、符号速率Rs和数据速率DR的关系 5、