[英]How to decode a (doubly) 'url-encoded' string in python
嘗試以下列方式解碼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))
由於雙重編碼。
您的輸入被編碼為double 。 使用 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'))
urllib.unquote_plus(urllib.unquote_plus(some_string)) FireShot3 (2).png
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.