首页 技术 正文
技术 2022年11月18日
0 收藏 362 点赞 2,989 浏览 2172 个字

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 unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values.
string must be a 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 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:

URL Quoting

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!!!

  URL Quoting

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

  URL Quoting

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

  URL Quoting

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,116
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,588
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,433
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,204
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,840
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,925