[英]How to decode a (doubly) 'url-encoded' string in python
Tried decoding a url-encoded
string in the following way尝试以下列方式解码url-encoded
字符串
some_string = 'FireShot3%2B%25282%2529.png'
import urllib
res = urllib.unquote(some_string).decode()
res
u'FireShot3+%282%29.png'
Original string is FireShot3 (2).png
.原始字符串是FireShot3 (2).png
。 Any help would be appreciated.任何帮助,将不胜感激。
Answer: urllib.unquote_plus(urllib.unquote_plus(some_string))
due to double encoding.答案: urllib.unquote_plus(urllib.unquote_plus(some_string))
由于双重编码。
Your input is encoded double .您的输入被编码为double 。 Using Python 3:使用 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 would need to be:使用 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.