urllib.quote

来源:互联网 发布:qc来电归属地数据库 编辑:程序博客网 时间:2024/05/21 06:33
Python的url编码函数是在类urllib库中,使用方法是:

编码: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 这下就好了。

0 0
原创粉丝点击