python2.7 urllib和urllib2
- 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的更多相关文章
- 详解:Python2中的urllib、urllib2与Python3中的urllib以及第三方模块requests
在python2中,urllib和urllib2都是接受URL请求的相关模块,但是提供了不同的功能.两个最显著的不同如下: 1.urllib2可以接受一个Request类的实例来设置URL请求的hea ...
- python2核心类库:urllib、urllib2的区别和使用
urllib/urllib2都是接受URL请求的相关模块区别:1.urllib2可以接受一个Request类的实例来设置URL请求的headers,urllib仅可以接受URL.这意味着,你不可以伪装 ...
- Python2中的urllib、urllib2和 Python3中的urllib、requests
目录 Python2.x中 urllib和urllib2 常用方法和类 Python3.x中 urllib requests Python2.x中 urllib和urllib2 urllib 和 ur ...
- 深入理解urllib、urllib2及requests
urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...
- Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 httplib模块 django和web服务器整合 wsgi模块 gunicorn模块
Python第十三天 django 1.6 导入模板 定义数据模型 访问数据库 GET和POST方法 SimpleCMDB项目 urllib模块 urllib2模块 ...
- python的httplib、urllib和urllib2的区别及用
慢慢的把它们总结一下,总结就是最好的学习方法 宗述 首先来看一下他们的区别 urllib和urllib2 urllib 和urllib2都是接受URL请求的相关模块,但是urllib2可以接受一个Re ...
- 关于urllib、urllib2爬虫伪装的总结
站在网站管理的角度,如果在同一时间段,大家全部利用爬虫程序对自己的网站进行爬取操作,那么这网站服务器能不能承受这种负荷?肯定不能啊,如果严重超负荷则会时服务器宕机(死机)的,对于一些商业型的网站,宕机 ...
- python3对urllib和urllib2进行了重构
python3对urllib和urllib2进行了重构,拆分成了urllib.request,urllib.response, urllib.parse, urllib.error等几个子模块,这样的 ...
- 理解urllib、urllib2及requests区别及运用
urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...
随机推荐
- codeforces#571Div2 D---Vus the Cossack and Numbers【贪心】
题目:http://codeforces.com/contest/1186/problem/D 题意:给定一个大小为$n$的浮点序列,这$n$个数的和为0. 现在对这个序列中的每个数,进行向上取整或向 ...
- ES6遍历器 生成器 学习整理
遍历器[迭代器](Iterator) 就是这样一种机制.它是一种接口,为各种不同的数据结构提供统一的访问机制.任何数据结构只要部署 Iterator 接口,就可以完成遍历操作(即依次处理该数据结构的所 ...
- hive,把一个表中计算好的数据,存到另一个外部表中
直接上代码: 第一部分: case class OrdPacsresult_obj(pk_dcpv: String, result_obj: String) 第二部分: def ordsubj: Un ...
- MySQL服务优化参数设置参考
l 通用类: key_buffer_size 含义:用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写). 影响:对于MyISAM表的影响不是很大,MyISAM会使用系统的缓存来存储 ...
- C++标准库分析总结(五)——<Deque、Queue、Stack设计原则>
本节主要总结标准库Deque的设计方法和特性以及相关迭代器内部特征 1.Deque基本结构 Deque(双向队列)也号称连续空间(其实是给使用者一个善意的谎言,只是为了好用),其实它使用分段拼接起来的 ...
- 页面tr和td的的隐藏与显示
<view:qrytr attributes="class=zcrzs"> </view:qrytr> var bd11 = $("tr[ ...
- ORBSLAM2单目初始化过程
ORBSLAM2单目初始化过程 转自博客:https://blog.csdn.net/zhubaohua_bupt/article/details/78560966 ORB单目模式的初始化过程可以分为 ...
- [ambari环境搭建](未完待续)
[安装] https://blog.csdn.net/Happy_Sunshine_Boy/article/details/86595945#commentBox https://www.jiansh ...
- 本周JavaScript学习小结
应组长杨老师号召,写个js阶段性学习小结. emmm这周学了Linux进程通讯,学正则表达式尝试完成第一次编程作业,中秋还去平潭露营(所以...js学得很少hhh). 现在还处于感性认识阶段,浏览了一 ...
- Filename too long Resolution
在git bash中,运行下列命令: git config --global core.longpaths true --global是该参数的使用范围,如果只对本版本库设置该参数,只要在上述命令中去 ...