URL Decode with Python 3

后端 未结 2 765
情话喂你
情话喂你 2020-12-05 09:07

Is there a way to URL decode a string in Python 3

to take something like this

id%253D184ff84d27c3613d%26quality%3Dmedium

and decod

相关标签:
2条回答
  • 2020-12-05 10:06

    Just use urllib.parse.unquote():

    >>> import urllib.parse
    >>> urllib.parse.unquote('id%253D184ff84d27c3613d%26quality%3Dmedium')
    'id%3D184ff84d27c3613d&quality=medium'
    >>> urllib.parse.unquote('id%3D184ff84d27c3613d&quality=medium')
    id=184ff84d27c3613d&quality=medium
    
    0 讨论(0)
  • 2020-12-05 10:06

    Try this:

    from urllib.parse import unquote
    s = 'id%253D184ff84d27c3613d%26quality%3Dmedium'
    unquote(unquote(s))
    

    It will return:

    > 'id=184ff84d27c3613d&quality=medium'
    
    0 讨论(0)
提交回复
热议问题