Is there any way in Python to transform this %CE%B1%CE%BB%20
into this αλ
which is its real representation?
replace('%20+', '') will replace '%20+' with empty string. Isn't just '%20' you need to replace? There's a lot more than %20 that you need to deal with.
The proper way of encoding a space in the query string of a URL is the + sign. See Wikipedia and the HTML specification. As such urllib. quote_plus() should be used instead when encoding just one key or value, or use urllib.
Use the re. sub() method to remove URLs from text, e.g. result = re. sub(r'http\S+', '', my_string) .
For python 2:
>>> import urllib2 >>> print urllib2.unquote("%CE%B1%CE%BB%20") αλ
For python 3:
>>> from urllib.parse import unquote >>> print(unquote("%CE%B1%CE%BB%20")) αλ
And here's code that works in all versions:
try: from urllib import unquote except ImportError: from urllib.parse import unquote print(unquote("%CE%B1%CE%BB%20"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With