Summary of common Python3 urllib. parse functions (urlencode, quote, quote_plus, unquote, unquote_plus, etc.), urllib. parse. unquote
This article describes the urllib. parse common functions of Python3. We will share this with you for your reference. The details are as follows:
1. Obtain url parameters
>>> From urllib import parse >>> url = r'https: // docs.python.org/3.5/search.html? Q = parse & check_keywords = yes & area = default '> parseResult = parse. urlparse (url) >>> parseResultParseResult (scheme = 'https', netloc = 'docs .python.org ', path ='/3.5/search.html ', params = '', query = 'q = parse & check_keywords = yes & area = default', fragment = '') >>> param_dict = parse. parse_qs (parseResult. query) >>> param_dict {'q': ['parse'], 'check _ keyword': ['yes'], 'area ': ['default'] >>>> q = param_dict ['q'] [0] >>> q'parse' # Note: the plus sign is decoded, sometimes it is not what we want> parse. parse_qs ('proxy = 183.222.102.178: 8080 & task = XXXXX | 5-3 + 2') {'proxy': ['183. 222.102.178: 8080 '], 'task': ['xxxxx | 5-3 2']}
2. urlencode
>>> from urllib import parse>>> query = { 'name': 'walker', 'age': 99, }>>> parse.urlencode(query)'name=walker&age=99'
3. quote/quote_plus
>>> From urllib import parse >>> parse. quote ('a & B/C') # unencoded slash 'a % 26b/C'> parse. quote_plus ('a & B/C') # encode the diagonal line 'a % 26b % 2Fc'
4. unquote/unquote_plus
From urllib import parse >>> parse. unquote ('1 + 2') # Do not decode the plus sign '1 + 2'> parse. unquote ('1 + 2') # decodes the plus sign into a space '1 2'
If you still want to ask why there is no urldecode, read example 1 five times. Pai_^