• urllib模块url编码和解码:

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

urllib.quote 说明:

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

urllib.quote_plus 说明: 

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

实例演示:

  1. In [18]: urllib.quote('abc def')
  2. Out[18]: 'abc%20def'
  3.  
  4. In [19]: urllib.quote_plus('abc def')
  5. Out[19]: 'abc+def'

2.urllib.urlencode

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

  实例演示:

  1. In [21]: urllib.urlencode({'username':'xixi','passward':'haha'})
  2. Out[21]: 'username=xixi&passward=haha'
  3.  
  4. In [23]: urllib.urlencode((('username','嘻嘻'),('passward','哈哈')))
  5. 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. 约瑟夫问题O(n)/O(mlogn)

    题面 略 题解 约瑟夫问题.编号000~n−1n-1n−1,每次拿第mmm个. O(n)O(n)O(n):f[n]f[n]f[n]表示幸存的人的编号,f[n]=(f[n−1]+m)%nf[n]=(f[ ...

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

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

  3. 【安卓进阶】Product Flavor基础玩法

    在安卓项目开发中,大多时候总是有测试环境.生产环境之类的区别,在不使用Product Flavor时,我们一般都是通过手工改动代码来实现测试环境.生产环境的切换. 这样就造成了项目管理上的不便,频繁的 ...

  4. sql server 综合使用的例子

    exec sp_helptext prosampleoldstyle_usp -- ============================================= -- ========= ...

  5. Linux ntp 时间同步服务配置

    一.基础环境 1.操作系统:CentOS 7.3 2.ntp:4.2.6 3.机器,服务端(192.168.1.210)客户端(192.168.1.211) 二.安装ntp yum -y instal ...

  6. Turn Off Windows Firewall Using PowerShell and CMD

    If you want to turn off the Windows Firewall, there are three methods. One is using the GUI which is ...

  7. Windows10下安装Ubuntu18.04LTS详细教程

    这篇文章分享自己在Windows10系统下安装VMware虚拟机,然后在VMware中安装Ubuntu 18.04 LTS的详细过程.之所以选择在虚拟机中安装Ubuntu,主要是可以不影响自己电脑的正 ...

  8. SpringBoot JPA懒加载异常 - com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy

    问题与分析 某日忽然发现在用postman测试数据时报错如下: com.fasterxml.jackson.databind.JsonMappingException: could not initi ...

  9. 2018-2019 20175234 实验三《敏捷开发与XP实践》实验报告

    目录 2018-2019 20175234 实验三<敏捷开发与XP实践>实验报告 实验内容 实验中的问题 码云链接 参考资料 2018-2019 20175234 实验三<敏捷开发与 ...

  10. 感知机模型到DNN模型

    参考资料 感知机模型:https://www.cnblogs.com/pinard/p/6042320.html DNN:https://www.cnblogs.com/pinard/p/641866 ...