How to decode a (doubly) 'url-encoded' string in python

前端 未结 2 542
轮回少年
轮回少年 2021-02-05 06:45

Tried decoding a url-encoded string in the following way

some_string = \'FireShot3%2B%25282%2529.png\'
import urllib
res = urllib.unquote(some_strin         


        
2条回答
  •  [愿得一人]
    2021-02-05 07:36

    Your input is encoded double. Using Python 3:

    urllib.parse.unquote(urllib.parse.unquote(some_string))
    

    Output:

    'FireShot3+(2).png'
    

    now you have the + left.

    Edit:

    Using Python 2.7 it of course is:

    urllib.unquote(urllib.unquote('FireShot3%2B%25282%2529.png'))
    

提交回复
热议问题