2

I have a link like below

http%253A%252F.....25252520.doc

How do i convert this to normal link in python?..the link has lots of encoded stuff..

Abul Hasnat
  • 1,541
  • 2
  • 16
  • 23

2 Answers2

4

Apply urllib.unquote twice:

>>> import urllib
>>> strs = urllib.unquote("http%253A%252F.....25252520.doc")
>>> urllib.unquote(strs)
'http:/.....25252520.doc'
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
  • 2
    And `urllib.parse.unquote` for python3.5+ https://docs.python.org/3.6/library/urllib.parse.html#urllib.parse.unquote – Desprit Jun 03 '20 at 08:36
2

Use urllib.unquote():

Replace %xx escapes by their single-character equivalent.

It looks as if you have a double or ever triple encoded URL; the http:// part has been encoded to http%253A%252F which decodes to http%3A%2F which in turn becomes http:/. The URL itself may contain another stage of encoding but you didn't share enough of the actual URL with us to determine that.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Although in OP's example, you have to unquote it _twice_. First, all those `%25` are unquoted to `%`, then the actual unquoting is done. – tobias_k Jun 25 '13 at 13:56