吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2970|回复: 14
收起左侧

[Python 转载] sina短链接api

  [复制链接]
yuanzhangzcc 发表于 2020-4-2 19:42
本帖最后由 yuanzhangzcc 于 2020-4-2 19:46 编辑


感觉最近论坛挺多的短链接转换软件
这里提供一个接口供大家使用

最近论坛出现了很多的短链接转换器,但是苦于没有api

所以这里给大家提供一个t.cn 新浪短链接的api,不需要登录,不需要appid

先贴代码

#coding=utf-8
#python 3.6.5
import requests
import os
import pandas as pd
import re

#request请求
#os 短链接复制
#pd 读取剪切板中的网址
#re 正则匹配

def sina_url(url):
        base_url = 'https://service.weibo.com/share/share.php?url=' + url + '&title=' + url
        header ={
                "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
        }
        res = requests.get(api_url,header)
        #匹配字符串scope.short_url = " http://t.cn/Ryh0P2j ";\
        match = r'scope.short_url = "[?\s+](.*)"'
        url_short = re.search(match,res.text)
        copy(url_short.group(1))

def copy(url_short):
    os.system('echo ' + url_short + '| clip')
    print(url_short)
    os.system("pause")

if __name__ == '__main__':
        url_long = list(pd.read_clipboard()) #读入剪切板数据
        if ( 'http://' in url_long[0] ) or ( 'https://' in url_long[0] ):   #读取
                sina_url(url_long[0])

如何使用?

  • python安装 requests包 和 pd包
    pip install requests
    pip install pandas

  • 复制想要转换的链接

  • 运行程序

  • 想要分享的地方粘贴

希望好心人制作一个exe版本的

制作思路

新浪微博分享的api
https://service.weibo.com/share/share.php?url=https://www.52pojie.cn&title=1
参数url和title必须
然后使用正则匹配页面中的短链接



编辑一下,附上运行图...
批注 2020-04-02 194602.jpg

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

克里空 发表于 2020-4-2 20:00
我来个,线上PHP版本的demo   http://t.malped.com/
wangyancun1999 发表于 2020-4-2 20:51
克里空 发表于 2020-4-2 20:00
我来个,线上PHP版本的demo   http://t.malped.com/

你搞错了,写错了,你自己去写个百度短链接试试能不能访问
头像被屏蔽
袁煜914 发表于 2020-4-2 19:51
bdcpc 发表于 2020-4-2 19:56
这个六六六
李大宽 发表于 2020-4-2 19:59
厉害👍
yangtong 发表于 2020-4-2 19:59
可以,支持下
ZHANGZHILING 发表于 2020-4-2 20:01
666,加油
凩茻MUMU 发表于 2020-4-2 20:21
pyinstaller不就可以打包成exe了么。很简单的
 楼主| yuanzhangzcc 发表于 2020-4-2 20:44
凩茻MUMU 发表于 2020-4-2 20:21
pyinstaller不就可以打包成exe了么。很简单的

我的库太多了,打包就成了200m多,加上没有虚拟环境
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 13:19

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表