如本表所示http://www.javascripter.net/faq/accentedcharacters.htm , escape()
和 encodeURI()
是有区别的。
我需要模仿 escape()
的行为,因为另一个系统需要它,但事实证明这对 Python 来说很复杂。
msg = "¿El mañana exitirá?"
# javascript: console.log(escape(msg)) # %BFEl%20ma%F1ana%20exitir%E1%3F
q = urllib.parse.quote(msg)
print(q) # %C2%BFEl%20ma%C3%B1ana%20exitir%C3%A1%3F
q = urllib.parse.quote(msg, encoding="unicode_escape")
print(q) # %5CxbfEl%20ma%5Cxf1ana%20exitir%5Cxe1%3F
如何让 Python 模仿 escape
?
最佳答案
事实证明,我非常接近:
msg = "¿El mañana exitirá?"
q = urllib.parse.quote(msg, encoding="raw_unicode_escape")
print(q) # %BFEl%20ma%F1ana%20exitir%E1%3F
关于javascript - 模仿 Javascript escape() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43694242/