赞
踩
最近发现了一个比较好玩的东西----github上的网页可以使用另外一个比较简短的域名
来实现跳转(实际上相当于重定向),这下可太好了,再也不要使用这么长的域名了
https://github.com/Cyberist-Edgar/PyQt/tree/master/PyQt%E7%99%BB%E5%BD%95%E7%95%8C%E9%9D%A2
相反,我们可以使用一个这么简单的域名就可以实现访问了
https://git.io/Jexuz
我去,这也可太方便了吧,其实实现起来尤其的方便,我们只要访问 这里, 输入想要缩短的url
便可以了
当然作为一个有理想,有志气的青年,当然就想着如何可以在不登录网页的时候输出就可以了,顺便还可以批量
生成,所以用代码简单的实现了一波:
import requests def shorten_github_url(ch_url): url = "https://git.io/create" base_url = "https://git.io/" response = requests.post(url, data={'url': ch_url}) if 'Invalid' in response.text: print(response.text) return None final_url = base_url + response.text return final_url if __name__ == "__main__": ch_url = input("Please input your url: ") url = shorten_github_url(ch_url) print(url)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。