简体   繁体   中英

URL Decode with Python 3

Is there a way to URL decode a string in Python 3

to take something like this

id%253D184ff84d27c3613d%26quality%3Dmedium

and decode it twice to get

id=184ff84d27c3613d&quality=medium

Just use urllib.parse.unquote() :

>>> import urllib.parse
>>> urllib.parse.unquote('id%253D184ff84d27c3613d%26quality%3Dmedium')
'id%3D184ff84d27c3613d&quality=medium'
>>> urllib.parse.unquote('id%3D184ff84d27c3613d&quality=medium')
id=184ff84d27c3613d&quality=medium

Try this:

from urllib.parse import unquote
s = 'id%253D184ff84d27c3613d%26quality%3Dmedium'
unquote(unquote(s))

It will return:

> 'id=184ff84d27c3613d&quality=medium'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM