服务粉丝

我们一直在努力
当前位置:首页 > 财经 >

利用Python实现B站自动签到

日期: 来源:kali黑客笔记收集编辑:priess

利用python实现B站自动签到,快速提高你的等级。签到内容包括,登录签到、 视频观看、5次投币(需消耗5个币)、分享视频(不会发在个人空间动态里)。

使用

  • 1、浏览器登入哔哩网站
  • 2、F12看到cookie的值粘贴即可

代码

# -*- coding: utf8 -*-

import requests
import json
import time
import random

# 填写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()

更多精彩文章 欢迎关注我们


相关阅读

  • 议题征集 | 看雪·第七届安全开发者峰会启动!

  • 看雪·第七届安全开发者峰会随着云计算、大数据、人工智能等新技术的融合越发深入,网络已经覆盖了人们生活的方方面面。随之而来的网络钓鱼、恶意软件、身份盗用、数据泄露等
  • 【IDA特训营】带你快速掌握 IDA 重要操作

  • 逆向工程作为一个新兴的领域,在软件维护中有着重要的作用。充分利用逆向工程技术就可以对现有系统进行改造,减少开发强度,提高软件开发效率,降低项目开发的经济成本,提高经济效益
  • 致敬!武汉大学第十届杰出校友!

  • 百卅光阴,学子盈室汇集一世英华,他们在各行各业栉风沐雨、谱写华章饮水思源,不忘师恩,反哺母校他们是武大校训精神的践行者和传承者3月23日,在庄严的樱顶老图书馆武汉大学第十届
  • World sees benefits of key concept

  • In the spring of 2015, during a state visit to Pakistan, his first to the country, President Xi Jinping delivered a speech at the nation's Parliament entitled "
  • Life丨Superhero back in action

  • Merely by uttering the magic word "Shazam", Billy Batson — a lucky teenager fictionalized in Hollywood's DC cinematic universe — transforms into a superpowere

热门文章

  • “复活”半年后 京东拍拍二手杀入公益事业

  • 京东拍拍二手“复活”半年后,杀入公益事业,试图让企业捐的赠品、家庭闲置品变成实实在在的“爱心”。 把“闲置品”变爱心 6月12日,“益心一益·守护梦想每一步”2018年四

最新文章

  • 对于人生真正重要事情的坚持!

  • [本文3612字,阅读约需11分钟]昨天写了一篇《孔乙己,时代,与你我的机会》,没想到收获了很多好问题,感觉一周的写作主题都有了。大概有哪几个呢?有小伙伴问:努力也找不到工作那是什么
  • 未来动物园

  • 未来——一个可以让人展开想象的词。未来是一个让人神往的地方,今天我坐在书桌上看着关于未来的书,心里突然蹦出一个想象:如果在未来我开了一个动物园会怎样?我的脑子里如江水一
  • 6 个令人惊艳的 ChatGPT 项目,开源了!

  • 公众号关注 “GitHubDaily”设为 “星标”,每天带你逛 GitHub!过去一周,技术圈的各个爆炸新闻,可以说是让我真正见证到了什么叫人间一日,AI 一年。首先是 New Bing 对所有用户放
  • 利用Python实现B站自动签到

  • 利用python实现B站自动签到,快速提高你的等级。签到内容包括,登录签到、 视频观看、5次投币(需消耗5个币)、分享视频(不会发在个人空间动态里)。使用1、浏览器登入哔哩网站2、F12
  • 干货 | API接口渗透测试技巧汇总

  • 作者:白河愁,来源:先知社区1 API 接口介绍1.1 RPC(远程过程调用)远程过程调用(英语:Remote Procedure Call,缩写为 RPC)是一个计算机通信协议。该协议允许运行于一台计算机的程序调用
  • 拒付赎金,法拉利遭受勒索软件攻击后数据泄露

  • 近日,法拉利证实其发生了一起网络事件,黑客能够访问其IT环境中的部分系统。这家意大利豪华跑车制造商在一份声明中表示,攻击者获得了对其网络的访问权限,并向其索要赎金,否则就将