bilibili自动每日签到投币任务升级脚本云函数版

功能

  • 登录签到
  • 视频观看
  • 5次投币(需消耗5个币)
  • 分享视频(不会发在个人空间动态里)

以上每天经验共65点经验。

使用

  • ==========================
  • 1、用浏览器用户登入B站
  • 2、新建一个标签页,点击F12打开开发者工具,输入URL访问 http://api.bilibili.com/x/space/myinfo
  • 3、找到上方network,看到cookie的值全部粘贴至代码中cookies变量中即可
  • 4、支持投币开关,设置coin_operated的变量,默认投币
  • 5、根据下方图片,配置腾讯云函数运行
  • ==========================

python代码

更新:在上版基础上增加了投币开关,改了部分代码,任务完成后会输出详细的结果数据

# -*- coding: utf-8 -*-
# date:2021/12/13
 
import requests
import json
import time
import random
 
# 填写cookie即可运行
'''
1、浏览器登入哔哩网站
2、访问 http://api.bilibili.com/x/space/myinfo
3、F12看到cookie的值粘贴即可
'''
cookies = ""
coin_operated = 1  # (投币开关,0不投币,1投币)
 
 
# 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)
    j = requests.get(url, cookies=cookie).json()
    username = j['data']['name']
    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)
    if coin_operated:
        days = int(int(sub_exp) / 65)
    else:
        days = int(int(sub_exp) / 15)
    coin = getCoin()
    msg = f"欢迎 {username}! 当前等级:" + str(level) + " ,当前经验:" + \
          str(current_exp) + ",升级还差 " + str(sub_exp) + \
          "经验,还需" + str(days) + "天," + "当前硬币数量:" + str(coin)
    return current_exp, 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()
    coin_count = 0
    for i in range(0, 10):
        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(i + 1) + ' ---- ' + str(bvid) + ' ---- ' + str(aid))
        toview(bvid)
        time.sleep(3)
        shareVideo(bvid)
        time.sleep(3)
        if coin_operated:
            while coin_count < min(coin_num, 5):
                coin_code = tocoin(bvid)
                if coin_code == 1:
                    coin_count += 1
                elif coin_code == -99:
                    return
        else:
            pass
        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)
    j = requests.post(url, data=data, cookies=cookie).json()
    code = j['code']
    if code == 0:
        print('看视频成功!')
    else:
        print('看视频失败!')
 
 
# 分享视频
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('分享成功!')
    else:
        print('分享失败!')
 
 
# 投币函数
def tocoin(bvid):
    coinNum = getCoin()
    if coinNum == 0:
        print('太穷了,硬币不够!')
        return -99
    url = "http://api.bilibili.com/x/web-interface/coin/add"
    data = {
        'bvid': bvid,
        'multiply': 1,
        'select_like': 1,
        '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) + ' 投币成功!')
        return 1
    else:
        print(str(bvid) + ' 投币失败!')
        return 0
 
 
# 开启任务运行
def run():
    exp1, msg = getInfo()
    print(msg)
    Task()
    exp2, c = getInfo()
    print(f'任务完成,获得经验{int(exp2) - int(exp1)}')
 
 
# 云函数使用
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()

腾讯云函数配置

给TA打赏
共{{data.count}}人
人已打赏
技术笔记

苹果MacCmsV10前端player_aaaa视频地址加密

2021-12-12 18:14:51

技术笔记

全自动刷步数并同步WX和ZFB腾讯云函数版

2021-12-15 17:54:05

声明 本站文章上的代码及教程皆来源于NOW世界(favnow.com),仅供学习交流,切勿用于非法用途。转载请备注来源!
如果您对此有任何有建树的想法都可以请您发送邮件至 cople@139.com 或点击右侧 私信:鲨鱼,我们将尽快处理!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索