浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

How to escape (percent-encode) a URL with Python « SaltyCrane Blog

How to escape (percent-encode) a URL with Python

import urllib

print urllib.quote_plus("http://www.yahoo.com/")
print urllib.quote_plus("Kruder & Dorfmeister")

Results:

http%3A%2F%2Fwww.yahoo.com%2F
Kruder+%26+Dorfmeister

It is easy to be drawn to the urlencode function in
the Python

urllib module documentation
. But for simple
escaping, only quote_plus, or
possibly quote is needed. I believe this is the
appropriate solution to

Python urlencode annoyance
and

O'Reilly's Amazon Hack #92
.

posted on 2012-03-18 23:10  lexus  阅读(327)  评论(0编辑  收藏  举报