2024-06-28 11:14:05 发布
网友
我从一个HTTP头得到了一个字符串,但它被转义了。。我可以使用什么函数来调整它的外观?
myemail%40gmail.com -> myemail@gmail.com
urllib.unquote()会是正确的方法吗?
我非常确定urllib的^{}是执行此操作的常见方法。
>>> import urllib >>> urllib.unquote("myemail%40gmail.com") 'myemail@gmail.com'
还有^{}:
Like unquote(), but also replaces plus signs by spaces, as required for unquoting HTML form values.
是的,看来^{}完成了这个任务。(一tested it against your example on codepad。)
在Python 3中,这些函数是^{}和^{}。
后者用于例如HTTP url中的查询字符串,其中空间字符() are traditionally encoded as plus character (+)和+被百分比编码为%2B。
+
%2B
除此之外,还有^{}将给定的编码字符串转换为bytes,当编码未知或编码数据是二进制数据时,可以使用该字符串。但是没有unquote_plus_to_bytes,如果需要,可以执行以下操作:
bytes
unquote_plus_to_bytes
def unquote_plus_to_bytes(s): if isinstance(s, bytes): s = s.replace(b'+', b' ') else: s = s.replace('+', ' ') return unquote_to_bytes(s)
有关使用unquote或unquote_plus的详细信息,请访问URL encoding the space character: + or %20。
unquote
unquote_plus
我非常确定urllib的^{} 是执行此操作的常见方法。
还有^{} :
是的,看来^{} 完成了这个任务。(一tested it against your example on codepad。)
在Python 3中,这些函数是^{} 和^{} 。
后者用于例如HTTP url中的查询字符串,其中空间字符(
) are traditionally encoded as plus character (
+
)和+
被百分比编码为%2B
。除此之外,还有^{} 将给定的编码字符串转换为
bytes
,当编码未知或编码数据是二进制数据时,可以使用该字符串。但是没有unquote_plus_to_bytes
,如果需要,可以执行以下操作:有关使用
unquote
或unquote_plus
的详细信息,请访问URL encoding the space character: + or %20。相关问题 更多 >
编程相关推荐