如何在python中解码(双重)'url-encoded'字符串 [英] How to decode a (doubly) 'url-encoded' string in python

查看:470
本文介绍了如何在python中解码(双重)'url-encoded'字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Tried decoding a url-encoded string in the following way

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

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

Original string is FireShot3 (2).png. Any help would be appreciated.

答案: urllib.unquote_plus(urllib.unquote_plus(some_string))由于采用了双重编码.

Answer: urllib.unquote_plus(urllib.unquote_plus(some_string)) due to double encoding.

推荐答案

您的输入编码为 double .使用Python 3:

Your input is encoded double. Using Python 3:

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

输出:

'FireShot3+(2).png'

现在您剩下+.

使用Python 2.7,它当然是:

Using Python 2.7 it of course is:

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

这篇关于如何在python中解码(双重)'url-encoded'字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆