99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁大數(shù)據(jù)時代不熬夜,不修仙,B站打怪升級腳本一鍵搞定
不熬夜,不修仙,B站打怪升級腳本一鍵搞定
2021-12-16
收藏

作者:某某白米飯

來源:Python 技術(shù)

在 B 站上看了進(jìn)擊的金廠長的投稿的視頻如:B 界等級修仙傳,B 界等級修魔傳等,覺得 B 站升級對小編這種白嫖黨 + 懶癌黨太不友好了,就碼了這篇 B 站升級腳本。

獲取個人信息

用自己的賬號登錄到 B 站并打開個人頁面,按 F12 控制面板。可以找到一個 https://api.bilibili.com/x/space/myinfo?jsonp=jsonp&callback=__jp0 的地址,從相應(yīng)的返回值來看,這就是個人資料的請求地址。并且把請求頭中的 cookie 復(fù)制到代碼中,讓我們可以正常用代碼登錄 B 站。

不熬夜,不修仙,B站打怪升級腳本一鍵搞定

這里的 cookie 是一串字符串,在 requests.get() 請求的時候肯定是要轉(zhuǎn)換為字典類型的。其中一個 bili_jct 比較關(guān)鍵,在后續(xù)操作中將被用到。

def convert_cookies_to_dict(cookies): cookies = dict([l.split("=", 1) for l in cookies.split("; ")]) return cookies

下面代碼就用上面轉(zhuǎn)換成字典的 cookie 獲取 B 站的個人資料。

def getInfo(cookie):
    url = "http://api.bilibili.com/x/space/myinfo" resp = requests.get(url, cookies=cookie).text
    myinfo = json.loads(resp)

    data = myinfo['data']
    mid = data['mid']
    name = data['name']
    level_exp = data['level_exp']
    current_level = level_exp['current_exp']
    current_exp = level_exp['current_exp']
    next_exp = level_exp['next_exp']
    sub_exp = int(next_exp) - int(current_exp)
    days = int(int(sub_exp)/70)
    coin = data['coins']
    print("{},你的等級是{},當(dāng)前經(jīng)驗(yàn)是{},下一級經(jīng)驗(yàn)是{},還需要{}天升級,有{}個硬幣".format(name, current_level,current_exp,next_exp,days,coin))

觀看視頻

因?yàn)樾【帉?shí)在是不想解析頁面,就在網(wǎng)上找了一個 B 站的 http://api.bilibili.cn/recommend 接口來獲取視頻地址。返回值是一個 json 串,這里面有 aid 和 bvid。

def getVideo(cookie):
    url = "http://api.bilibili.cn/recommend" resp = requests.get(url, cookies=cookie).text data = json.loads(resp)
    
    list_length = len(data['list'])
    result = [] for i in range(list_length):
        bvid = data['list'][i]['bvid']
        aid = data['list'][i]['aid']
        result.append({'bvid': bvid, 'aid': aid}) return result

獲取到 aid 和 bvid 后,打開播放視頻頁面會有發(fā)送心跳鏈接到服務(wù)器,這個應(yīng)該可以看做是看過視頻的。

不熬夜,不修仙,B站打怪升級腳本一鍵搞定
def view(bvid, aid, bili_jct, playedTime): url = "https://api.bilibili.com/x/click-interface/web/heartbeat" header = { "origin": "https://www.bilibili.com", "referer": "https://www.bilibili.com/video/"+bvid, "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", "cookie": cookies

    }
    data = { 'aid': aid, 'bvid': bvid, 'played_time': playedTime, 'csrf': bili_jct
    }
    resp = requests.post(url, data = data ,headers=header).text
    json_data = json.loads(resp)
    code = json_data['code']
    time.sleep() if code == 0:
        print('視頻觀看成功,bvid 號為:' + bvid) else:
        print('視頻觀看失敗,bvid 號為:' + bvid)

投幣

投幣比較簡單,只有 4 個參數(shù),但是每天就只能投 5 個幣,得 50 經(jīng)驗(yàn)。

不熬夜,不修仙,B站打怪升級腳本一鍵搞定
def coin(bvid, aid, csrf):
    
    url = "https://api.bilibili.com/x/web-interface/coin/add" data = { 'aid': aid, 'multiply': 1, 'select_like': 1, 'cross_domain': 'true', 'csrf': csrf
    }
    header = { "origin": "https://www.bilibili.com", "referer": "https://www.bilibili.com/video/"+bvid, "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", "cookie": cookies

    }

    resp = requests.post(url, headers=header, data=data).text data = json.loads(resp)
    code = data['code'] if code == 0:
        print("投幣成功") else:
        print('投幣失敗')

分享視頻

在分享到動態(tài)的時候,可以看到有一個 share 的地址,然后小編就用這個試了好幾次都沒有成功,只能求助萬能的 github。

不熬夜,不修仙,B站打怪升級腳本一鍵搞定

上面這個地址沒成功,都是分享失敗,下面的截圖是 github 的,分享成功。

不熬夜,不修仙,B站打怪升級腳本一鍵搞定
def share( bvid, csrf): url = 'https://api.bilibili.com/x/web-interface/share/add' data = { 'csrf': csrf, 'bvid': bvid
    }
    header = { 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8', "Connection": "keep-alive", "origin": "https://t.bilibili.com", "referer": 'https://t.bilibili.com', "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", "cookie": cookies

    }
    resp = requests.post(url, data=data, headers=header).text
    json_data = json.loads(resp)
    code = json_data['code'] if code == 0:
        print('視頻分享成功') else:
        print('視頻分享失敗')

總結(jié)

python 小腳本總能在想不到的地方有意外的驚喜。人生苦短,認(rèn)為本文還可以的朋友點(diǎn)個贊和再看。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }