首页
社区
课程
招聘
[原创]哔哩 等级升级脚本
2021-12-8 20:56 24562

[原创]哔哩 等级升级脚本

2021-12-8 20:56
24562

更新

于2022年1月18号更新

功能

- 登录签到

- 视频观看

- 5次投币(需消耗5个币)

- 分享视频(不会发在个人空间动态里)


以上每天经验共65点经验。可挂云函数定时任务执行脚本。


使用

'''

1、浏览器登入哔哩网站

2、访问 http://api.bilibili.com/x/space/myinfo

3、在F12从network 选项卡里面取到cookie值就可以了,值粘贴即可

'''

代码

# -*- coding: utf8 -*-

import requests
import json
import time
import random

# 填写cookie即可运行
'''
1、浏览器登入哔哩网站
2、访问 http://api.bilibili.com/x/space/myinfo
3、F12看到cookie的值粘贴即可
'''
cookies = ""


# cookie转字典
def extract_cookies(cookies):
    global csrf
    cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
    csrf = cookies['bili_jct']
    return cookies


# 银币数
def getCoin():
    cookie = extract_cookies(cookies)
    url = "http://account.bilibili.com/site/getCoin"
    r = requests.get(url, cookies=cookie).text
    j = json.loads(r)
    money = j['data']['money']
    return int(money)


# 个人信息
def getInfo():
    global uid
    url = "http://api.bilibili.com/x/space/myinfo"
    cookie = extract_cookies(cookies)
    r = requests.get(url, cookies=cookie).text
    j = json.loads(r)
    uid = j['data']['mid']
    level = j['data']['level']
    current_exp = j['data']['level_exp']['current_exp']
    next_exp = j['data']['level_exp']['next_exp']
    sub_exp = int(next_exp)-int(current_exp)
    days = int(int(sub_exp)/65)
    coin = getCoin()
    times = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    msg = "【bili】"+str(times)+"\nWelcome! Current level is "+str(level)+"\nCurrent experience are "+str(current_exp)+"\nNot far from upgrading "+str(sub_exp)+"\nneed "+str(days)+" days\n" + \
        "Remaining silver coins are "+str(coin)
    print(msg)
    return msg


# 推荐动态
def getActiveInfo():
    url = "http://api.bilibili.com/x/web-interface/archive/related?aid=" + \
        str(7)
    cookie = extract_cookies(cookies)
    r = requests.get(url, cookies=cookie).text
    j = json.loads(r)
    return j


# 推荐动态第二种方式
def getVideo():
    random_page = random.randint(0, 167)
    url = "http://api.bilibili.cn/recommend?page="+str(random_page)
    cookie = extract_cookies(cookies)
    r = requests.get(url, cookies=cookie).text
    j = json.loads(r)
    return j


# 投币 分享5次
def Task():
    coin_num = getCoin()
    # 需要投币的个数
    num = 5
    if coin_num <= num:
        num = coin_num
    coin_count = 0
    count = 0
    while True:
        j = getVideo()
        list_len = len(j['list'])
        random_list = random.randint(1, list_len-1)
        bvid = j['list'][random_list]['bvid']
        aid = j['list'][random_list]['aid']
        print(str(count)+' ---- '+str(bvid)+' ---- '+str(aid))
        count = count+1
        toview(bvid)
        time.sleep(5)
        shareVideo(bvid)
        time.sleep(5)
        if coin_count < num:
            coin_code = tocoin(aid, bvid)
            if coin_code == -99:
                return
        if coin_code == 1:
            coin_count = coin_count+1
        if coin_count == num:
            break
        print('----------------------')


# 观看视频【不会点赞投币】
def toview(bvid):
    playedTime = random.randint(10, 100)
    url = "https://api.bilibili.com/x/click-interface/web/heartbeat"
    data = {
        'bvid': bvid,
        'played_time': playedTime,
        'csrf': csrf
    }
    cookie = extract_cookies(cookies)
    r = requests.post(url, data=data, cookies=cookie).text
    j = json.loads(r)
    code = j['code']
    if code == 0:
        print('watching viedo successful!')
    else:
        print('watching viedo failed!')


# 分享视频
def shareVideo(bvid):
    url = "https://api.bilibili.com/x/web-interface/share/add"
    data = {
        'bvid': bvid,
        'csrf': csrf
    }
    cookie = extract_cookies(cookies)
    # 需要请求头
    header = {
        "Content-Type": "application/x-www-form-urlencoded",
        "Connection": "keep-alive",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38",
    }
    r = requests.post(url, data=data, cookies=cookie, headers=header).text
    j = json.loads(r)
    code = j['code']
    if code == 0:
        print('share  successful!')
    else:
        print('share failed!')


# 投币函数
def tocoin(aid, bvid):
    coinNum = getCoin()
    if coinNum == 0:
        print('not enough coin !')
        return -99
    url = "https://api.bilibili.com/x/web-interface/coin/add"
    headers = {
        'authority': 'api.bilibili.com',
        'method': 'POST',
        'path': '/x/web-interface/coin/add',
        'scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'no-cache',
        'content-type': 'application/x-www-form-urlencoded',
        'origin': 'https://www.bilibili.com',
        'pragma': 'no-cache',
        'referer': 'https://www.bilibili.com/video/'+str(bvid)+'?spm_id_from=444.41.0.0',
        'sec-ch-ua': '"Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-site',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
    }
    data = {
        'aid': aid,
        'multiply': 1,
        'select_like': 1,
        'cross_domain': 'true',
        'csrf': csrf
    }
    cookie = extract_cookies(cookies)
    r = requests.post(url, data=data, headers=headers, cookies=cookie).text
    j = json.loads(r, strict=False)
    code = j['code']
    if code == 0:
        print(str(bvid)+' toaddcoin successful !')
        return 1
    else:
        print(str(bvid)+' toaddcoin failed!')
        return 0


# 一键三连
def toall(bvid):
    coinNum = getCoin()
    if coinNum == 0:
        print('not enough coin !')
        return -99
    url = "http://api.bilibili.com/x/web-interface/archive/like/triple"
    data = {
        'bvid': bvid,
        'csrf': csrf
    }
    cookie = extract_cookies(cookies)
    r = requests.post(url, data=data, cookies=cookie).text
    j = json.loads(r)
    code = j['code']
    if code == 0:
        print(str(bvid)+' toaddcoin successful !')
        return 1
    else:
        print(str(bvid)+' toaddcoin failed!')
        return 0


# 开启任务运行
def run():
    getInfo()
    Task()


# 云函数使用
def main_handler(event, context):
    print("Received event: " + json.dumps(event, indent=2))
    print("Received context: " + str(context))
    run()
    return("------ end ------")


if __name__ == '__main__':
    run()

申明

仅供学习参考交流,切勿做违法之事,注意法律上的可行性。


[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

最后于 2022-1-18 14:04 被Y6blNU1L编辑 ,原因:
收藏
点赞4
打赏
分享
最新回复 (13)
雪    币: 5082
活跃值: (4389)
能力值: ( LV5,RANK:65 )
在线值:
发帖
回帖
粉丝
gamehack 2021-12-8 21:17
2
0
感谢分享,学习了!
雪    币: 66
活跃值: (210)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Ultramarine 2021-12-8 21:32
3
0
感謝分享,学习下
雪    币: 573
活跃值: (949)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
ChengQing 2021-12-9 10:55
4
0

没事了,感谢分享

最后于 2021-12-9 11:04 被ChengQing编辑 ,原因:
雪    币: 573
活跃值: (949)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
ChengQing 2021-12-9 10:56
5
0

感谢分享

最后于 2021-12-9 11:04 被ChengQing编辑 ,原因:
雪    币: 20
活跃值: (166)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Lmxczq 2021-12-11 06:57
6
0
感谢分享
雪    币: 1668
活跃值: (630)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
星空 2021-12-15 20:05
7
0
http://api.bilibili.com/x/space/myinfo,已经失效了
雪    币: 892
活跃值: (1485)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Y6blNU1L 2021-12-16 21:13
8
0
星空 http://api.bilibili.com/x/space/myinfo,已经失效了
没有呀,先登入进去,在访问这个链接,在F12从network 选项卡里面取到cookie值就可以了。
雪    币: 20
活跃值: (166)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Lmxczq 2021-12-30 21:51
9
0
2021 12-30 视频投币好像失效了
雪    币: 510
活跃值: (88)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hickwu 2022-1-8 12:46
10
0
试了下确认投币 失败 toaddcoin failed! 
可否分享下具体研究历程? 是  chrome 上分析 http 请求? 还是整到 app/小程序 之类的了? 
雪    币: 892
活跃值: (1485)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Y6blNU1L 2022-1-12 11:05
11
1
hickwu 试了下确认投币 失败 toaddcoin failed! 可否分享下具体研究历程? 是  chrome 上分析 http 请求? 还是整到 app/小程序 之类的了?

您好,就是通过网页抓包得到的接口,目前投币于2021-12-30失效。

最后于 2022-1-12 11:08 被Y6blNU1L编辑 ,原因:
雪    币: 892
活跃值: (1485)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Y6blNU1L 2022-3-25 13:37
12
0
脚本距今依旧有效。2022-3-25
雪    币: 1451
活跃值: (14614)
能力值: ( LV12,RANK:380 )
在线值:
发帖
回帖
粉丝
SSH山水画 3 2022-3-25 13:53
13
0
Y6blNU1L 脚本距今依旧有效。2022-3-25
辛苦养的号废了,现在一打开APP就是推送看不懂的视频,你还我黑丝
雪    币: 892
活跃值: (1485)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Y6blNU1L 2022-3-29 20:21
14
0
SSH山水画 辛苦养的号废了,现在一打开APP就是推送看不懂的视频,你还我黑丝
啊?我的没事呀,这个好像不会改变大数据的推算的算法吧。
游客
登录 | 注册 方可回帖
返回