📅  最后修改于: 2020-05-13 11:04:47             🧑  作者: Mango
先决条件:URL缩短程序及其API | 1
让我们讨论使用同一pyshorteners
模块的更多URL缩短器。
from pyshorteners import Shortener
ACCESS_TOKEN = '82e8156..e4e12c6'
url = 'http://www.google.com'
url_shortener = Shortener('Bitly', bitly_token = ACCESS_TOKEN)
print ("Short URL is {}".format(url_shortener.short(url)))
扩展URL的代码:
from pyshorteners import Shortener
ACCESS_TOKEN = '82e8156...c1dce4e12c6'
url = 'http://bit.ly/2OGRcfW'
url_expander = Shortener('Bitly', bitly_token = ACCESS_TOKEN)
print ("Long URL is {}".format(url_expander.expand(url)))
注意:将显示一条消息,“ 您的API访问权限当前已禁用”。单击此处启用它。
缩短网址的代码:
from pyshorteners import Shortener
# uid表示用户ID,key表示API密钥.
url = 'http://www.google.com'
url_shortener = Shortener('Adfly', uid ='20727891', key ='b8de8e0...5a2381241c', type ='int')
print ("Short URL is {}".format(url_shortener.short(url)))
from pyshorteners import Shortener
url = 'http://www.google.com'
url_shortener = Shortener('Osdb')
print ("SHORT URL is {}".format(url_shortener.short(url)))
from pyshorteners import Shortener
url = 'http://www.google.com'
url_shortener = Shortener('Dagd')
print ("Short URL is {}".format(url_shortener.short(url)))