python+pyshorteners—长短链接(网址)转换

目录

长短链接转换

长网址转短网址


长短链接转换

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=dabf93

你可能感兴趣的:(爬虫,网络,python,开发语言)