赞
踩
目录
- import pyshorteners as psn
- import requests
-
-
- def longurl_to_shorturl(longurl):
- # 长链接转短链接
- shorturl = psn.Shortener().chilpit.short(url)
- return shorturl
-
-
- def shorturl_to_longurl(shorturl):
- # 短链接转长链接
- res = requests.head(shorturl)
- return res.headers.get('Location')
-
-
- if __name__ == '__main__':
- url = 'https://hanyu.baidu.com/shici/detail?from=kg1&highlight=%E6%80%A8%E7%9B%9B%E5%B9%B4%E4%B9%8B%E8%8E%AB%E5%BD%93%E3%80%82&pid=dabf9384e3ff4fe8bc7b9f64385c1015&srcid=51369'
- short_url = longurl_to_shorturl(url)
- print(f'长链接转为短链接结果:{short_url}')
-
- long_url = shorturl_to_longurl(short_url)
- print(f'短链接转为长链接结果:{long_url}')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。