Transform URL string into normal string in Python ( to space etc)

前端 未结 3 952
半阙折子戏
半阙折子戏 2020-12-14 15:07

Is there any way in Python to transform this %CE%B1%CE%BB%20 into this αλ which is its real representation?

3条回答
  •  独厮守ぢ
    2020-12-14 15:28

    For python 2:

    >>> import urllib2
    >>> print urllib2.unquote("%CE%B1%CE%BB%20")
    αλ 
    

    For python 3:

    >>> from urllib.parse import unquote
    >>> print(unquote("%CE%B1%CE%BB%20"))
    αλ
    

    And here's code that works in all versions:

    try:
        from urllib import unquote
    except ImportError:
        from urllib.parse import unquote
    
    print(unquote("%CE%B1%CE%BB%20"))
    

提交回复
热议问题