我想模仿我们在Python中使用的JS中的decodeURIComponent并取消逃逸。
例如,我得到了以下字符串:
%25D7%2590%25D7%2591%25D7%2592
在JS中,我可以这样做:
decodeURIComponent(unescape('%25D7%2590%25D7%2591%25D7%2592'))
和get:אבג
我在Python里找不到任何方法,我用的是“旋风网”,如果是相关的话.
发布于 2017-12-11 12:43:34
Python中有urllib.parse.unquote
(或者Python2中有urlparse.unquote
)可以这样做。
但是,我不明白为什么您发布的字符串是用户编码的两次。因为只使用decodeURIComponent
(没有unescape
)就可以解码单个用户编码的字符串。
无论如何,Python版本应该是:
from urllib.parse import unquote # For Python 2 use: from urlparse import unquote
# decode twice because the string has been encoded twice.
unquote(unquote('%25D7%2590%25D7%2591%25D7%2592'))
对于单个urlencoded字符串,只需要使用unquote
一次。
https://stackoverflow.com/questions/47749168
复制相似问题