如何将%3A和%2F转换为:和/在python中的url中?

os8fio9y  于 2022-11-26  发布在  Python
关注(0)|答案(4)|浏览(298)

如何转换URL中的替换(%3A和%2F ...)。

网址

https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29

必需的URL

https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Sat Aug 06 2016 11:42:36 GMT+0530 (India Standard Time)
我在想有没有简单的方法可以做到这一点?

mgdq6dx1

mgdq6dx11#

python 2.7中,使用urllib。取消引用:

>>> import urllib
>>> urllib.unquote(urllib.unquote('https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29'))
'https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Fri Aug 05 2016 11:40:14 GMT+0530(India Standard Time)'

python 3+中,使用urllib。

>>> from urllib.parse import unquote
>>> unquote(unquote("https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29"))
'https://url/login_data.php?username=user&categoryid=0&URL=https://url/&TIME=Fri Aug 05 2016 11:40:14 GMT+0530(India Standard Time)'
wgeznvg7

wgeznvg72#

看一看urllib.parse.unquote:“将%xx转义替换为它们的等效单字符。”

bfhwhh0e

bfhwhh0e3#

对于python3,

import urllib.parse
urllib.parse.unquote_plus("https://url/login_data.php?username=user&categoryid=0&URL=https%3A%2F%2Furl%2F%26TIME%3DFri%2520Aug%252005%25202016%252011%3A40%3A14%2520GMT%2B0530%28India%2520Standard%2520Time%29")
unhi4e5o

unhi4e5o4#

我们将在纽伦堡、弗尔特、埃尔兰根和埃姆登等地为您提供专业、全面的仓库、仓库、工厂以及所有私人和私营仓库的重建服务。我们的服务涵盖所有重建工作,并为您在纽伦堡、弗尔特、埃尔兰根、施瓦巴赫和埃姆登等地提供服务。
建筑物玻璃化改造基础设施建设建筑物装修装饰装修冬季园林建筑服务

相关问题