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相关的操作,但他们提供不同的功 ...
随机推荐
- HaspMap和ConcurrentHashMap
参考自:http://www.importnew.com/28263.html HaspMap和ConcurrentHashMap(康科瑞特哈希迈普) Java7 HashMap 不支持并发操作,Ha ...
- jenkins安装和国内镜像配置
直接替换 $JENKINS_HOME/updates/default.json 成腾讯云的地址即可: JENKINS_HOME=xxxxxxxxx sed -i 's/http:\/\/updates ...
- win32通用控件
1.标准控件 可以在win32窗口程序中添加资源脚本来给程序添加标准控件: 具体操作为:新建资源脚本 ->在.rc文件中添加控件 ->给控件绑定事件: 常用的标准控件: ...
- (2)打鸡儿教你Vue.js
var obj = {} Object.defineProperty(obj, 'msg', { // 设置 obj.msg = "1" 时set方法会被系统调用 参数分别是设置后 ...
- java1.8新特性之stream流式算法
在Java1.8之前还没有stream流式算法的时候,我们要是在一个放有多个User对象的list集合中,将每个User对象的主键ID取出,组合成一个新的集合,首先想到的肯定是遍历,如下: List& ...
- P1065 作业调度方案——小模怡情,大模伤身
P1065 作业调度方案 一个有点费手的“小”%%拟: 题都差点没读明白……: 每个机器所能完成的工序是不一样的: 每个物品完成工序的机器是指定的: 按照题面说的按时间轴推下去就行了: 没有时间上界有 ...
- php cookie 操作
创建 cookie <?php setcookie(); ?> 取回 Cookie 的值 <?php // Print a cookie echo $_COOKIE["us ...
- Alpha项目冲刺! Day2-产出
各个成员今日完成的任务 林恩:任务分工,博客撰写,设计设置等模块 杨长元:学习安卓本地数据库建立 李震:如何写登录界面登录页面,如何下载模板 胡彤:连接服务端 寇永明:提供页面 王浩:提供页面 李杰: ...
- train loss和test loss
train loss 不断下降,test loss不断下降,说明网络仍在学习;(最好的)train loss 不断下降,test loss趋于不变,说明网络过拟合;(max pool或者正则化)tra ...
- Flutter移动电商实战 --(41)详细页_数据接口的调试
建立数据模型层,我们的业务逻辑分开,然后进行后台数据的调试 生成model类 json数据: { "code": "0", "message" ...