Summary of common functions of urllib. parse in Python3

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.