- 所需模块:
requests
- 测试版本:3.7.1
- 实现代码:
import requests
def geturl(url):
res = requests.head(url)
url = res.headers.get('location')
return url
- 测试:
import requests
def geturl(url):
res = requests.head(url)
url = res.headers.get('location')
return url
print(geturl('http://url.cn/5NdpZhY'))
'''输出
https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=8090805&hosteuin=owvPNeEA7w4z7c**&songmid=004ZyE0M1JpB7U&type=0&appsongtype=1&_wv=1
'''