如何在Python上将文本转换为URL语法?
我想将Python字符串转换为URL语法 比如说如何在Python上将文本转换为URL语法?,python,url,Python,Url,我想将Python字符串转换为URL语法 比如说 >>> u'한글'.encode('utf-8') '\xed\x95\x9c\xea\xb8\x80' to '%ed%95%9c%ea%b8%80' 当然,这取决于终端或源文件是UTF-8。“安全”的拼写应该是urllib.quote(u'\ud55c\uae00'.encode('utf-8'))。 >>> import urllib2 >>> urllib2.quote('한글')
>>> u'한글'.encode('utf-8')
'\xed\x95\x9c\xea\xb8\x80' to '%ed%95%9c%ea%b8%80'
当然,这取决于终端或源文件是UTF-8。“安全”的拼写应该是
urllib.quote(u'\ud55c\uae00'.encode('utf-8'))
。
>>> import urllib2
>>> urllib2.quote('한글')
'%ED%95%9C%EA%B8%80'