Python for URL decoding

Source: Internet
Author: User

Import Urllibrawurl=xxxurl=urllib.unquote (Rawurl)

Module used: Urllib

Function used: Urllib.unquote ()

Case

Import"%e6%b2%b3%e6%ba%90"= urllib.unquote (rawurl) Print URL

Output

Heyuan

Problem extension

Urllib.unquote () is intended to decode the URL encoding, which corresponds to the function of the encoding function urllib.quote ()

>>> Import urllib>>> urllib.quote ("Heyuan") '%e6%b2%b3%e6%ba%90

Why do URLs need to be encoded and decoded?

Usually if something needs to be coded, it means that something is not suitable for transmission. There are a variety of reasons, such as size too large to contain privacy data. For URLs, the reason for encoding is because some characters in the URL cause ambiguity.

For example, the URL parameter string uses the Key=value key value pair to pass the parameter, separating the key-value pairs with a & symbol, such as/S?Q=ABC&ie=utf-8. If your value string contains = or &, then it is bound to cause the server parsing error to receive the URL, so the ambiguous & and = symbol must be escaped, that is, encoded.

Another example is that the URL is encoded in ASCII instead of Unicode, which means that you cannot include any non-ASCII characters in the URL, such as Chinese. Otherwise, Chinese can cause problems if the client browser and the server-side browser support different character sets.

Python for URL decoding

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.