如何在Python中进行URL解码?

13

给出以下内容:
It%27s%20me%21

将其解码并转换为普通文本?


1
当你谷歌搜索时,你找到了什么? - S.Lott
15
@S.Lott,当我谷歌搜索时,我找到了这个页面!! - priestc
3个回答

23

在Python2中

>>> import urlparse
>>> urlparse.unquote('It%27s%20me%21')
"It's me!"

在Python3中

>>> import urllib.parse
>>> urllib.parse.unquote('It%27s%20me%21')
"It's me!"

12

你可以查看 urllib.unquoteurllib.unquote_plus。这将解决你的问题。技术上来说,url的“编码”是使用 & 和 ? 字符将参数传递到url中的过程(例如:www.foo.com?x=11&y=12)。


5

使用urllib中的unquote方法。

>>> from urllib import unquote
>>> unquote('It%27s%20me%21')
"It's me!"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接