This article mainly introduces the urllib of Python3. common parse functions, combined with examples, analyze the usage skills of functions such as urlencode, quote, quote_plus, unquote, and unquote_plus. if you need them, refer to the following example to describe the urllib of Python3. common parse functions. 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.
For more information about Python3's urllib. parse common functions, see PHP!