Python urllib.quote

转:

编码:urllib.quote(string[, safe]),除了三个符号“_.-”外,将所有符号编码,后面的参数safe是不编码的字符, 使用的时候如果不设置的话,会将斜杠,冒号,等号,问号都给编码了。 如下: >>> import urllib >>> print urllib.quote("http://neeao.com/index.php?id=1") http%3A//neeao.com/index.PHP%3Fid%3D1 这样在使用urllib.urlopen打开编码后的网址的时候,就会报错了。 设置不编码的符号: >>> print urllib.quote("http://neeao.com/index.php?id=1",":?=/") http://neeao.com/index.php?id=1 这下就好了。

 

posted on 2017-08-23 19:41  TMatrix52  阅读(567)  评论(0编辑  收藏  举报

导航