在Python3中,可以使用urllib.parse.unquote函数进行URL解码(urldecode)。下面是一个简单的示例:
from urllib.parse import unquote
url = 'https%3A%2F%2Fwww.example.com%2Fsearch%3Fq%3Dpython%26page%3D1'
decoded_url = unquote(url)
print(decoded_url)
输出结果:
https://www.example.com/search?q=python&page=1
在上面的示例中,我们首先导入了unquote函数,然后传入需要解码的URL字符串。unquote函数会将URL字符串中的特殊字符(如%3A)解码为其原始的ASCII字符(如:),返回解码后的URL字符串。
请注意,在Python 2.x中,urldecode函数被称为unquote函数,使用方法与上述示例相同。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: centos7怎么配置python3环境