How to convert the replace(%3A and %2F ...) in the url.
URLhttps://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29
Required URL
https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Sat Aug 06 2016 11:42:36 GMT+0530 (India Standard Time)
I was wondering is there any simple way to do this?
Method #1 : Using split() ' and return the first part of split for result.
In Python 3+, You can URL encode any string using the quote() function provided by urllib. parse package. The quote() function by default uses UTF-8 encoding scheme.
The replace_urls() method in Python replaces all the URLs in a given text with the replacement string.
In python 2.7
, use urllib.unquote:
>>> import urllib
>>> urllib.unquote(urllib.unquote('https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29'))
'https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Fri Aug 05 2016 11:40:14 GMT+0530(India Standard Time)'
In python 3+
, use urllib.parse.unquote
>>> from urllib.parse import unquote
>>> unquote(unquote("https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29"))
'https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Fri Aug 05 2016 11:40:14 GMT+0530(India Standard Time)'
Take a look at urllib.parse.unquote: "Replace %xx escapes by their single-character equivalent."
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