【问题标题】:How to decode a (doubly) 'url-encoded' string in python如何在python中解码(双重)“url编码”字符串
【发布时间】:2015-02-10 12:11:32
【问题描述】:

尝试通过以下方式解码url-encoded 字符串

some_string = 'FireShot3%2B%25282%2529.png'
import urllib
res = urllib.unquote(some_string).decode()
res
u'FireShot3+%282%29.png'

原始字符串为FireShot3 (2).png。任何帮助将不胜感激。

回答: urllib.unquote_plus(urllib.unquote_plus(some_string)) 由于双重编码。

【问题讨论】:

标签: python urlencode urldecode


【解决方案1】:

您的输入被编码。使用 Python 3:

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

输出:

'FireShot3+(2).png'

现在你有+了。

编辑:

使用 Python 2.7,它需要:

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

【讨论】:

  • unqoute_plus 处理+ 字符。
【解决方案2】:

urllib.unquote_plus(urllib.unquote_plus(some_string)) FireShot3 (2).png

【讨论】:

    猜你喜欢
    • 2016-01-13
    • 2011-09-09
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 2010-11-13
    • 2023-04-11
    • 2017-11-01
    • 1970-01-01
    相关资源
    最近更新 更多