Skip to main content

Posts

Showing posts from March, 2017

Python: How to Unescape String (decodeURIComponent in JavaScript)

Decoding We can use urllib module to do this. This is in Python 2.7x — and Python 3+ (added). #!/usr/bin/env python2 """urllib module - Python 2.7x""" import urllib # ENCODED STRING THE_ENCODED_STRING = "https%3A%2F%2Flalala.com%2Flalala%3Fla%3Dla%26lala%3Dlala" # DECODED STRING THE_DECODED_STRING = urllib.unquote(THE_ENCODED_STRING) print(THE_DECODED_STRING) # OUTPUT https://lalala.com/lalala?la=la&lala=lala ➡️ Documentation for urllib.unquote() Python 2 utility . """ Python 3+ """ import urllib.parse # ENCODED STRING THE_ENCODED_STRING = "https%3A%2F%2Flalala.com%2Flalala%3Fla%3Dla%26lala%3Dlala" # DECODED STRING THE_DECODED_STRING = urllib.parse.unquote(THE_ENCODED_STRING) print(THE_DECODED_STRING) # OUTPUT https://lalala.com/lalala?la=la&lala=lala ➡️ Documentation for urllib.parse.unquote() Python 3 utility . Encoding The opposite of that function is url...
Monkey Raptor uses cookies for analytics, advertisements, and functionality. Privacy Policy