Suppose I have the following string:
\"http://earth.google.com/gallery/kmz/women_for_women.kmz?a=large\"
Is there some function or module t
Python 2's urllib.quote_plus, and Python 3's urllib.parse.quote_plus
url = "http://earth.google.com/gallery/kmz/women_for_women.kmz?a=large"
# Python 2
urllib.quote_plus(url)
# Python 3
urllib.parse.quote_plus(url)
outputs:
'http%3A%2F%2Fearth.google.com%2Fgallery%2Fkmz%2Fwomen_for_women.kmz%3Fa%3Dlarge'
Are you looking for urllib.quote or urllib.quote_plus? Note that you do not quote the entire url string as you mentioned in the question. You normally quote the part in the path or after the query string. Whichever you are going to use in the application.
Available in the Windows platform
#! python3.6
from urllib.parse import quote
# result: http://www.oschina.net/search?scope=bbs&q=C%E8%AF%AD%E8%A8%80
quote('http://www.oschina.net/search?scope=bbs&q=C语言',safe='/:?=&')