Decode escaped characters in URL
Using urllib
package (import urllib
) :
Python 2.7
From official documentation :
urllib.unquote(string)
Replace
%xx
escapes by their single-character equivalent.Example:
unquote('/%7Econnolly/')
yields'/~connolly/'
.
Python 3
From official documentation :
urllib.parse.unquote(string, encoding='utf-8', errors='replace')
[…]
Example:
unquote('/El%20Ni%C3%B1o/')
yields'/El Niño/'
.
Decode a url and store to a string with special characters
System.Net.WebUtility.UrlDecode works with .Net 4 Client profiles only
string value_string = Uri.UnescapeDataString(e.Url.Query); wil work for .net 4 applications
Encode / decode URLs
You can do all the URL encoding you want with the net/url module. It doesn't break out the individual encoding functions for the parts of the URL, you have to let it construct the whole URL. Having had a squint at the source code I think it does a very good and standards compliant job.
Here is an example (playground link)
package main
import (
"fmt"
"net/url"
)
func main() {
Url, err := url.Parse("http://www.example.com")
if err != nil {
panic("boom")
}
Url.Path += "/some/path/or/other_with_funny_characters?_or_not/"
parameters := url.Values{}
parameters.Add("hello", "42")
parameters.Add("hello", "54")
parameters.Add("vegetable", "potato")
Url.RawQuery = parameters.Encode()
fmt.Printf("Encoded URL is %q\n", Url.String())
}
Which prints-
Encoded URL is "http://www.example.com/some/path/or/other_with_funny_characters%3F_or_not/?vegetable=potato&hello=42&hello=54"
URL decode special characters - äåö
The string is Latin1 encoded
NSString *string = @"f%F6rv%E5nad";
NSString *result = [string stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
NSLog(@"%@", result); // förvånad
Related Topics
Start a Function at Given Time
What Does -1 Mean in Numpy Reshape
How to Clear the Screen in Python
How to Print Variables Without Spaces Between Values
How to Intercept Calls to Python's "Magic" Methods in New Style Classes
Pandas Dataframe Stored List as String: How to Convert Back to List
Python Class Instance Variables and Class Variables
"Cloning" Row or Column Vectors
Python' Is Not Recognized as an Internal or External Command
How to Increase the Cell Width of the Jupyter/Ipython Notebook in My Browser
Finding Median of List in Python
Replace() Method Not Working on Pandas Dataframe
Most Efficient Way of Making an If-Elif-Elif-Else Statement When the Else Is Done the Most
Access Elementtree Node Parent Node
What Are the Differences Between JSON and Simplejson Python Modules