B站 自动投币 需要登录后的cookie

原文链接: B站 自动投币 需要登录后的cookie

上一篇: cheerio 爬取 B站 视频热门视频的bv号

下一篇: nodejs 发送qq邮件 nodemailer

b站经验获取

如何获得经验值?

up-91104e1e1a9eb6f53032788cdc2582e1967.png

投币前

up-0b03429704a0b1a76b688c85ae4b717d7e8.png

投币后

up-7863240ca29beacda4bb94bda64a704e8da.png

csrf对应的cookie字段

up-3502d353e097fbe53c09fb0c0ede92ef89b.png

投币和点赞需要重写headers中的referer, 不然会出错, 即请求是由视频页面发出的

投币

// 投币
export async function coin(aid, multiply = 1, select_like = 0) {
  const url = "https://api.bilibili.com/x/web-interface/coin/add"
  headers['referer'] = `https://www.bilibili.com/video/${enc(aid)}`
  const data = {
    aid, // av的id号
    multiply,  // 硬币数目
    select_like, // 是否同时喜欢
    cross_domain: true, // 跨域
    csrf
  }
  let resp = await axios.post(
    url, data, {headers},
  )
  return resp.data
}

点赞

// 点赞
export async function like(aid, like = 1) {
  headers['referer'] = `https://www.bilibili.com/video/${enc(aid)}`
  const data = {
    aid, //498566183 497918057
    like, // 1 点赞,2 取消点赞
    csrf
  }

  const url = 'https://api.bilibili.com/x/web-interface/archive/like'
  let resp = await axios.post(
    url, data, {headers},
  )
  return resp.data
}

获得b站首页的html

export async function getHtml(url = bilibili_url) {
  const headers = {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "referrer": "https://www.bilibili.com",
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36',
  }
  const resp = await axios.get(url, {headers})
  return resp.data
}

设置action, 将secrets作为环境变量注入到env中

name: everyPush
on: [push]
# on:
#   schedule:
# * is a special character in YAML so you have to quote this string
#     - cron:  '*/15 * * * *'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: bilibili-auto-update
        run: |
          yarn install
          yarn test
        env:
          BILIBILI_COOKIE: ${{ secrets.BILIBILI_COOKIE }}

获取env中的变量

import {env} from "process";
const BILIBILI_COOKIE = env.BILIBILI_COOKIE
const headers = {
  "origin": "https://www.bilibili.com",
  "referer": "https://www.bilibili.com/video/BV1HK411575w?spm_id_from=333.851.b_62696c695f7265706f72745f646f756761.2",
  "accept-encoding": "gzip, deflate, br",
  "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
  "content-length": "94",
  "accept": "*/*",
  "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
  "sec-fetch-dest": "empty",
  "sec-fetch-mode": "cors",
  "sec-fetch-site": "same-site",
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36',
  'cookie': BILIBILI_COOKIE
}
const s = headers['cookie']

let re = /bili_jct=(.*?);/;
let list = re.exec(s);
const csrf = list[1];
// const csrf = '';
export {
  headers,
  csrf
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值