s ='Tara%2520Stiles%2520Living'
如何将其转换为:
Tara Stiles Living
答案 0 :(得分:14)
您需要使用urllib.unquote
,但似乎需要使用两次:
>>> import urllib
>>> s = 'Tara%2520Stiles%2520Living'
>>> urllib.unquote(urllib.unquote(s))
'Tara Stiles Living'
在取消引用一次之后,您的“%2520”变为“%20”,其中的“n”再次变为“”(空格)。
答案 1 :(得分:7)
答案 2 :(得分:4)
>>> import urllib
>>> s = 'Tara%2520Stiles%2520Living'
>>> t=urllib.unquote_plus(s)
>>> print t
Tara%20Stiles%20Living
>>> urllib.unquote_plus(t)
'Tara Stiles Living'
>>>
答案 3 :(得分:0)
import urllib
s = 'Tara%2520Stiles%2520Living'
t=''
while s<>t: s,t=t,urllib.unquote(s)
答案 4 :(得分:0)
如果您使用的是Python,则应使用urllib.parse.unquote(url),如以下代码所示:
import urllib
url = "http://url-with-quoted-char:%3Cspan%3E%20%3C/span%3E"
print(url)
print(urllib.parse.unquote(url))
此代码将输出以下内容:
>>> print(url)
http://url-with-quoted-char:%3Cspan%3E%20%3C/span%3E
>>> print(urllib.parse.unquote(url))
http://url-with-quoted-char:<span> </span>