URL Quoting
【URL Quoting】
The URL quoting functions focus on taking program data and making it safe for use as URL components by quoting special characters and appropriately encoding non-ASCII text. They also support reversing these operations to recreate the original data from the contents of a URL component.
URL quoting函数作用是将数据能够作为url的一部分,包括处理特殊字符,及编码非ASCII文本。quoting函数也支持逆转以还原数据。
urllib.parse.quote(string, safe='/', encoding=None, errors=None)
Replace special characters in string using the %xx escape. Letters, digits, and the characters '_.-' are never quoted.
Note that quote(string, safe, encoding, errors) is equivalent to quote_from_bytes(string.encode(encoding, errors), safe).
Example: quote('/El Ni駉/') yields '/El%20Ni%C3%B1o/'.
urllib.parse.quote_plus(string, safe='', encoding=None, errors=None)- Like
quote(), but also replace spaces by plus signs, as required for quoting HTML form values when building up a query string to go into a URL. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to'/'. - Example:
quote_plus('/El Ni駉/')yields'%2FEl+Ni%C3%B1o%2F'. - 在quote的基础上,把空格变为'+',连'/'也会被转义。
urllib.parse.unquote(string, encoding='utf-8', errors='replace')- string must be a
str. - encoding defaults to
'utf-8'. errors defaults to'replace', meaning invalid sequences are replaced by a placeholder character. - Example:
unquote('/El%20Ni%C3%B1o/')yields'/El Ni駉/'.
urllib.parse.unquote_plus(string, encoding='utf-8', errors='replace')- Like
unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values. - string must be a
str. - Example:
unquote_plus('/El+Ni%C3%B1o/')yields'/El Ni駉/'.
urllib.parse.urlencode(query, doseq=False, safe='', encoding=None, errors=None, quote_via=quote_plus)
Convert a mapping object or a sequence of two-element tuples, which may contain str or bytes objects, to a percent-encoded ASCII text string.
The resulting string is a series of key=value pairs separated by '&' characters, where both key and value are quoted using the quote_via function. By default, quote_plus() is used to quote the values, which means spaces are quoted as a '+' character and ‘/’ characters are encoded as %2F, which follows the standard for GET requests (application/x-www-form-urlencoded). An alternate function that can be passed as quote_via is quote(), which will encode spaces as %20 and not encode ‘/’ characters. For maximum control of what is quoted, use quote and specify a value for safe.
The safe, encoding, and errors parameters are passed down to quote_via (the encoding and errors parameters are only passed when a query element is a str).
To reverse this encoding process, parse_qs() and parse_qsl() are provided in this module to parse query strings into Python data structures.
【Example】
1、Here is an example session that uses the GET method to retrieve a URL containing parameters:

2、The following example uses the POST method instead. Note that params output from urlencode is encoded to bytes before it is sent to urlopen as data:
POST encode后的数据要转换为bytes!!!

3、The following example uses an explicitly specified HTTP proxy, overriding environment settings:

4、The following example uses an explicitly specified HTTP proxy, overriding environment settings:

URL Quoting的更多相关文章
- (转)Python3 模块3之 Urllib之 urllib.parse、urllib.robotparser
原文:https://blog.csdn.net/qq_36148847/article/details/79153738 https://blog.csdn.net/zly412934578/art ...
- python学习笔记——urllib库中的parse
1 urllib.parse urllib 库中包含有如下内容 Package contents error parse request response robotparser 其中urllib.p ...
- clean-css
What is clean-css? Clean-css is a fast and efficient Node.js library for minifying CSS files. Accord ...
- 笔记-urllib-parse
笔记-urllib-parse 1. 简介模块官方解释This module defines a standard interface to break Uniform Resource Locato ...
- 小白学 Python 爬虫(14):urllib 基础使用(四)
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- HTML URL地址解析
通过JavaScript的location对象,可获取URL中的协议.主机名.端口.锚点.查询参数等信息. 示例 URL:http://www.akmsg.com/WebDemo/URLParsing ...
- URL安全的Base64编码
Base64编码可用于在HTTP环境下传递较长的标识信息.在其他应用程序中,也常常需要把二进制数据编码为适合放在URL(包括隐藏表单域)中的形式.此时,采用Base64编码不仅比较简短,同时也具有不可 ...
- Android业务组件化之URL Scheme使用
前言: 最近公司业务发展迅速,单一的项目工程不再适合公司发展需要,所以开始推进公司APP业务组件化,很荣幸自己能够牵头做这件事,经过研究实现组件化的通信方案通过URL Scheme,所以想着现在还是在 ...
- ASP.NET Core的路由[1]:注册URL模式与HttpHandler的映射关系
ASP.NET Core的路由是通过一个类型为RouterMiddleware的中间件来实现的.如果我们将最终处理HTTP请求的组件称为HttpHandler,那么RouterMiddleware中间 ...
随机推荐
- 抽象类和接口 static final finalize
抽象类 任何含有一个或多个抽象方法的类都必须声明成抽象类,用关键字abstract. 抽象类没有对象,即一个抽象类不能用new来直接实例化. 不能定义抽象构造方法或抽象静态方法.(但是可以创建父类引用 ...
- java mvc web 项目web.xml头改错了,死活加载不上springMvc的jar
Description Resource Path Location TypeOne or more constraints have not been satisfied. ...
- MyEclipse Spring 学习总结一 Spring IOC容器
一.Spring IOC容器---- Spring AllicationContext容器 程序的结构如下: 1.首先在MyEclipse 创建创建Java Project 2.创建好后,添加spin ...
- OC基础—多态(超级简单)
前言: oc中的指针类型变量有两个:一个是编译时类型,一个是运行时类型,编译时类型由声明该变量是使用的类型决定,运行时类型由实际赋给该变量的对象决定.如果编译时类型和运行时类型不一致,就有可能出现多态 ...
- Spring学习 Ioc篇(一 )
一直以来忙于项目的开发,Spring虽然不用,一直想系统地学习一下,想看看它的源码,都没有时间,这段时间比较充裕,就索性先把Spring学习下,熟悉各个功能再去探究它内部的实现.就从Ioc篇开始学习. ...
- 【学+原】CSS3的2D动画 ——仿NOMOS手表
看CSS3妙味课堂中有一课是介绍如何做钟表界面,然后三根针都能随着时间转动,然后自己在那个简易的版本上做了一些进一部改进. 最关键的知识点应该是transform-origin这个样式,要选对旋转的中 ...
- H5课程大纲
K1模块课程: 课程模块 课程阶段 课程内容 K1 模块 第1阶段 认识前端开发 环境配置.使用标签的分类.写法及使用规范CSS样式的使用.各类常见样式Photoshop使用16大常用样式盒模型.语义 ...
- Spark Streaming、HDFS结合Spark JDBC External DataSouces处理案例
场景:使用Spark Streaming接收HDFS上的文件数据与关系型数据库中的表进行相关的查询操作: 使用技术:Spark Streaming + Spark JDBC External Data ...
- JSTL+MyEclipse8.5+Tomcat配置
使用JSTL的时候需要配置,即导入stdandard.jar和jstl.jar包,并在web.xml下对jstl进行配置.下面是使用步骤: 1. 解压jakarta-taglibs-standard- ...
- jquery radio取值,checkbox取值,select取值及选中
jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值 var item = $('in ...