分享个python 脚本 使用ai进行B站硬核答题
因为懒所有脚本没有做一键就运行,需要懂一点抓包,还有python需要ai ,我用的是deepseek ,结果是82分。前一次用了个免费的千问7b就38分。所以建议使用deepseek,不过deepseek需要实名认证,还需要充点钱就1块就可以了,忘记了新人有没有免费送token,有就不用充还有实名了
下面就是脚本需要做的事情了
脚本需要你提供 headerscookies access_key csrf
这四个值通过抓包获取
还有ai的api_key如果用deepseek只需要补充api_key如果是其他api就自行修改model和api
下面是抓包
准备好抓包后,进入硬核答题,最好是选择,知识,历史,和体育。自己答第一题,找这个获取问题的url
"https://api.bilibili.com/x/senior/v1/question"的请求 这个请求就全部包含headerscookies access_key csrf四个值了
上面准备好后
手机不要退出答题界面,一定在那里。启用脚本,直到答完100道后,在手机上答题随便选一个答案,
这时候有可能直接出现答完的报告显示你多少分,有可能出现第101道题,这时候滑动手机后退页面就会出现答完的报告了
```
import hashlib
import time
import urllib.parse
from curl_cffi import requests //魔改的requests 库,普通的requests 应该是被b站拒绝的
def appsign(params):
appkey = '1d8b6e7d45233436'
appsec = '560c52ccd288fed045859ed18bffd973'
params.update({'appkey': appkey})
params = dict(sorted(params.items()))
query = urllib.parse.urlencode(params)
sign = hashlib.md5((query + appsec).encode()).hexdigest()
params.update({'sign': sign})
return params
headers = {
}
cookies = {
}
access_key = "..."
csrf = "..."
def get_question():
url = "https://api.bilibili.com/x/senior/v1/question"
params = {
"access_key": access_key,
"csrf": csrf,
"disable_rcmd": "0",
"mobi_app": "android",
"platform": "android",
"statistics": "{\"appId\":1,\"platform\":3,\"version\":\"8.12.0\",\"abtest\":\"\"}",
"ts": "1726121484",
"web_location": "333.790",
}
params = appsign(params)
response = requests.get(url, headers=headers, cookies=cookies, params=params, impersonate='chrome101')
if response.status_code == 200:
data = response.json().get('data')
return data
def ai_request(content):
api_key = '...'
model = 'deepseek-chat'
system_prompt = ''
url = "https://api.deepseek.com/chat/completions"
headers_ = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
"Accept": "*/*",
}
data_ = {
"model": model,
"temperature": 0,
"messages": [
{
"role": "system",
"content": system_prompt,
},
{
"role": "user",
"content": content,
}
]
}
try:
response = requests.post(url, headers=headers_, json=data_)
response.raise_for_status()
json_data = response.json()
if json_data:
return json_data['choices']['message']['content']
except Exception as e:
print(str(e))
return ''
def ai_query(question_data):
answers = for i in question_data["answers"]]
option_str = "\n".join(answers)
prompt = f'请查看下面的问题,并告诉我答案,不要返回答案本身,一定要仅返回正确答案的选项号,如果第一答案正确就返回1 \n问题是:\n{question_data["question"]}\n\n选项是:\n{option_str}'
content = ai_request(prompt)
index = -1
try:
index = int(content)
except:
if content in answers:
index = answers.index(content)
if index > 0:
index = index - 1
return {
"id": question_data['id'],
"ans_text": question_data['answers']['ans_text'],
"ans_hash": question_data['answers']['ans_hash'],
"question": question_data['question'],
"question_num": question_data['question_num'],
}
def submit(answer_data):
url = 'https://api.bilibili.com/x/senior/v1/answer/submit'
data = {
'access_key': access_key,
'ans_hash': answer_data['ans_hash'],
'ans_text': answer_data['ans_text'],
'csrf': csrf,
'disable_rcmd': '0',
'id': answer_data['id'],
'mobi_app': 'android',
'platform': 'android',
'statistics': '{"appId":1,"platform":3,"version":"8.12.0","abtest":""}',
'ts': '1726121484',
}
data = appsign(data)
response = requests.post(url, headers=headers, data=data, impersonate='chrome101')
if response.status_code == 200:
print(f'第{answer_data["question_num"]}题:{answer_data["question"]} 提交了答案:{answer_data["ans_text"]}\n')
if answer_data['question_num'] < 100:
return True
have_next = True
while have_next:
data = get_question()
if data:
try:
content = ai_query(data)
if content:
have_next = submit(content)
if have_next:
print('等待中......')
time.sleep(2)
except Exception as e:
print(e)
time.sleep(5)``` 如果第一次分数不够的话,第二次是不需要重新抓包的,只需要进行答题后,直接运行脚本就可以了 。
还有app应该是要用粉色那个普通B站app客户端,至于其他客户端不知道能不能 牛逼
我之前也想过做,但是没想明白怎么答题
没想到能接入gpt
页:
[1]