Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert the %3A and %2F to : and / in the url in python?

How to convert the replace(%3A and %2F ...) in the url.
URL
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

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?

like image 255
anderson Avatar asked Aug 06 '16 06:08

anderson


People also ask

How do you split a URL in Python?

Method #1 : Using split() ' and return the first part of split for result.

How do I convert a string to a URL in Python?

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.

How do you change the URL in Python?

The replace_urls() method in Python replaces all the URLs in a given text with the replacement string.


2 Answers

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)'
like image 160
Nehal J Wani Avatar answered Sep 28 '22 11:09

Nehal J Wani


Take a look at urllib.parse.unquote: "Replace %xx escapes by their single-character equivalent."

like image 36
Karin Avatar answered Sep 28 '22 11:09

Karin