• urllib模块url编码和解码:

1.urllib.quote,urllib.quote_plus ,urllib.unquote ,urllib.unquote_plus

urllib.quote 说明:

quote(s, safe='/')
quote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted. RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters. reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | "," Each of these characters is reserved in some component of a URL,
but not necessarily in all of them. By default, the quote function is intended for quoting the path
section of a URL. Thus, it will not encode '/'. This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.
(END)

urllib.quote_plus 说明: 

quote_plus(s, safe='')
Quote the query fragment of a URL; replacing ' ' with '+'

实例演示:

In [18]: urllib.quote('abc def')
Out[18]: 'abc%20def' In [19]: urllib.quote_plus('abc def')
Out[19]: 'abc+def'

2.urllib.urlencode

urlencode(query, doseq=0)
Encode a sequence of two-element tuples or dictionary into a URL query string. If any values in the query arg are sequences and doseq is true, each
sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the
parameters in the output will match the order of parameters in the
input.
(END)

  实例演示:

In [21]: urllib.urlencode({'username':'xixi','passward':'haha'})
Out[21]: 'username=xixi&passward=haha' In [23]: urllib.urlencode((('username','嘻嘻'),('passward','哈哈')))
Out[23]: 'username=%E5%98%BB%E5%98%BB&passward=%E5%93%88%E5%93%88'

  

最新文章

  1. C# 数组的交集、差集、并集
  2. 初探Socket
  3. 移动互联网广告 - 第十更 - 广告投放运营 DashBoard - 2016/12/10
  4. Cacti学习笔记一:基本安装和配置
  5. 用cmd命令合并N个文件
  6. POJ 1922
  7. [HIve - LanguageManual] Union
  8. struts2中#,$,%的用法以及el,ognl表达式的用法
  9. Time complexity of ArrayList in Java
  10. Selenuim+Python之元素定位总结及实例说明
  11. css实现六边形图片(最简单易懂方法实现高逼格图片展示)
  12. Trie树(字典树)推荐文章
  13. C# 消息队列-MSMQ
  14. ruby数组操作方法汇总
  15. wishhack 玩法概览
  16. Oracle服务器和客户端安装在同一台机器的情况
  17. websocket+Django+python+paramiko实现web页面执行命令并实时输出
  18. [daily] 使用diff和patch打补丁
  19. PAT-GPLT训练集 L2-002 链表去重
  20. jsfl 常用自定义方法

热门文章

  1. Python Django 版本对应表
  2. tsql 通过row_number() over() 产生行号
  3. PHP流程控制之if语句多种嵌套
  4. PHP实现多文件上传的一些简单方法
  5. python一些实用的小工具
  6. Angular2日期格式化
  7. 数据结构实验之图论十:判断给定图是否存在合法拓扑序列(SDUT 2140)
  8. docker 静默安装mysql
  9. docker容器里面执行top报“TERM environment variable not set.”
  10. 更加方便的使用git上传自己的代码