• 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'

  

python2.7 urllib和urllib2的更多相关文章

  1. 详解:Python2中的urllib、urllib2与Python3中的urllib以及第三方模块requests

    在python2中,urllib和urllib2都是接受URL请求的相关模块,但是提供了不同的功能.两个最显著的不同如下: 1.urllib2可以接受一个Request类的实例来设置URL请求的hea ...

  2. python2核心类库:urllib、urllib2的区别和使用

    urllib/urllib2都是接受URL请求的相关模块区别:1.urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL.这意味着,你不可以伪装 ...

  3. Python2中的urllib、urllib2和 Python3中的urllib、requests

    目录 Python2.x中 urllib和urllib2 常用方法和类 Python3.x中 urllib requests Python2.x中 urllib和urllib2 urllib 和 ur ...

  4. 深入理解urllib、urllib2及requests

    urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...

  5. Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 httplib模块 django和web服务器整合 wsgi模块 gunicorn模块

    Python第十三天   django 1.6   导入模板   定义数据模型   访问数据库   GET和POST方法    SimpleCMDB项目   urllib模块   urllib2模块 ...

  6. python的httplib、urllib和urllib2的区别及用

    慢慢的把它们总结一下,总结就是最好的学习方法 宗述 首先来看一下他们的区别 urllib和urllib2 urllib 和urllib2都是接受URL请求的相关模块,但是urllib2可以接受一个Re ...

  7. 关于urllib、urllib2爬虫伪装的总结

    站在网站管理的角度,如果在同一时间段,大家全部利用爬虫程序对自己的网站进行爬取操作,那么这网站服务器能不能承受这种负荷?肯定不能啊,如果严重超负荷则会时服务器宕机(死机)的,对于一些商业型的网站,宕机 ...

  8. python3对urllib和urllib2进行了重构

    python3对urllib和urllib2进行了重构,拆分成了urllib.request,urllib.response, urllib.parse, urllib.error等几个子模块,这样的 ...

  9. 理解urllib、urllib2及requests区别及运用

    urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...

随机推荐

  1. location对象方法(assign()、reload()、replace())

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Hive的自定义函数

    功能: 通过人的生日,算出人的生肖和星座. 先在hive中创建一个表: 往这表中导入数据: 导入的数据为: 可以成功查询: 编写自定义函数代码:如下 package cn.tendency.wenzh ...

  3. sql server 标量函数的用法

    函数的内容是把汉字转换成拼音 select dbo.uf_GetSpellCode( book_class) from BOOK_MSG

  4. jq 字符串转数组

    一般我们在添加关键词时  会添加几组关键词     上传时怎么取值呢 取值时用以下格式 就能取到值 var FTag = "" //AAA,BBB if (FTag1 != &qu ...

  5. 常见的时间字符串与timestamp之间的转换 时间戳

    这里说的字符串不是一般意义上的字符串,是指在读取日期类型的数据时,如果还没有及时解析字符串,它就还不是日期类型,那么此时的字符串该怎么与时间戳之间进行转换呢? ① 时间字符串转化成时间戳 将时间字符串 ...

  6. java四种对象引用类型

    java四种对象引用类型 对象的强.软.弱和虚引用 在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序 ...

  7. BZOJ3781小B的询问

    莫队裸题. 维护的时候有的打法是利用(a-1)^2==a^2-2*a+1转移,也可以,但是通用性不太够. 下面的打法就是先把这个点的贡献删掉,然后更新这个点,再把这个点的贡献加回来,这种解法更加通用一 ...

  8. 标准6轴机器人正反解(1)-坐标系和MDH参数表

    刚来新公司不久,部门给安排了新人作业,我被分到的任务是求标准6轴机器人的正反解,以及利用就近原则选择最优解.从今天开始,逐步将这部分内容总结出来: 本文以及后续文章均使用改进DH法: 连杆坐标系: 坐 ...

  9. Java 方法与数组

    方法 什么是方法? 方法定义:方法(Method),函数(function),其实就指一个特定的功能操作,程序中完成独立功能,可重复使用的一段代码的集合. 方法的定义 方法定义格式: [修饰符] 返回 ...

  10. 火焰图工具 SystemTap

    1. 安装 SystemTap 1. 首先安装内核开发包和调试包: # rpm -ivh kernel-debuginfo-common-($version).rpm # rpm -ivh kerne ...