-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于 wbi 接口鉴权 -403 问题 #290
Comments
具体体现
|
我也遇到这个问题了,但是以前没有,我觉得是b站反爬策略更新了 |
是反爬更新了 |
目测路径带 |
下周就要答辩了,突然出现这个问题,好崩溃 |
用爬虫答辩的吗,是自动收集信息之类?现在接口不是完全不能用,间隔时间长点还能获取到数据。或许你可以先在本地爬好多份数据,答辩的时候展示一下。 |
要用到限制的接口?如果你急用还是可以解决的,加我qq3531890582 |
import hashlib
import time
from functools import reduce
import httpx
from bilibili_api import HEADERS
def getMixinKey(ae):
oe = [46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52]
le = reduce(lambda s, i: s + ae[i], oe, "")
return le[:32]
def md5(s: str):
return hashlib.md5(s.encode(encoding='utf-8')).hexdigest()
def split(s: str):
return s.split("/")[-1].split(".")[0]
def encWbi():
resp = httpx.get("https://api.bilibili.com/x/web-interface/nav")
wbi_img: dict = resp.json()["data"]["wbi_img"]
fe = wbi_img.get("img_url")
he = wbi_img.get("sub_url")
de = split(fe)
pe = split(he)
me = getMixinKey(de + pe)
ve = int(time.time())
Ae = f"ids=3449&pf=0&wts={ve}"
Me = md5(Ae + me)
return Me, ve
def test(uid: int):
Me, ve = encWbi()
resp = httpx.get(
url="https://api.bilibili.com/x/space/wbi/acc/info",
params={
"mid": str(uid),
"token": "",
"platform": "web",
"web_location": "1550101",
"w_rid": Me,
"wts": str(ve)
},
headers=HEADERS
)
try:
data = resp.json()
name = data["data"]["name"]
print(f"{name} UID: {uid}")
return True
except:
print(data)
return False
count = 0
succeed = 0
while True:
count += 1
if test(434334701):
succeed += 1
print(f"{100 * succeed / count}%") 成功率只有 52% |
到家,52%可还行?我来试试看搓一份吧 |
意思是,每次根据要传入的参数还要给出一个w_rid,算法就在b站页面的代码里吗 |
我已经改好了XD |
细说 |
import hashlib
import time
from functools import reduce
import httpx
HEADERS = {"User-Agent": "Mozilla/5.0", "Referer": "https://www.bilibili.com"}
def getMixinKey(ae):
oe = [46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41,
13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52]
le = reduce(lambda s, i: s + ae[i], oe, "")
return le[:32]
def md5(s: str):
return hashlib.md5(s.encode(encoding='utf-8')).hexdigest()
def split(s: str):
return s.split("/")[-1].split(".")[0]
def encWbi(params: dict):
resp = httpx.get("https://api.bilibili.com/x/web-interface/nav")
wbi_img: dict = resp.json()["data"]["wbi_img"]
img_url: str = wbi_img.get("img_url")
sub_url: str = wbi_img.get("sub_url")
img_value = split(img_url)
sub_value = split(sub_url)
me = getMixinKey(img_value + sub_value)
wts = int(time.time())
params["wts"] = wts
Ae = "&".join([f'{key}={value}' for key, value in params.items()])
w_rid = md5(Ae + me)
return w_rid, wts
def main(uid: int):
url_params = {"mid": uid}
w_rid, wts = encWbi(url_params)
params = {
"w_rid": w_rid,
"wts": wts,
}
params.update(url_params)
resp = httpx.get(
url="https://api.bilibili.com/x/space/wbi/acc/info",
params=params,
headers=HEADERS
)
print(resp.url, resp.json())
main(uid=558830935) |
emm,我去写pr了?刚放学好累,先吃饭 |
辛苦了 |
话说如果每次请求都重新获取 wbi 的 MixinKey 将严重拖慢速度吧,有哪里可以当作项目的环境变量存起来吗.jpg 以及需要检测下 nav 的那个 wbi_img_url 多久换一次 |
受不了了,立 flag +1,为什么传api只传url,不能整个扔过去吗... |
什么意思 |
@Drelf2018 能麻烦你有空的话test一下吗?我看看待会发release... |
from bilibili_api.utils.utils import get_api
API = get_api("user")
print(API["info"]["info"]) 你看看吧,接口信息都有的。 |
我说的是传入 request 的时候 |
我还是没看懂,你想用 json 文件里的 from bilibili_api.utils.utils import get_api
API = get_api("user")
async def func():
api = API["info"]["info"]
if api["wbi"]:
...
params = {"mid": self.__uid, "w_rid": ..., "wts": ...}
return await request(
"GET", url=api["url"], params=params, credential=self.credential
) 这个意思吗 |
from bilibili_api.utils.utils import get_api
API = get_api("user")
api = API["info"]["info"]
return await request(api, params, crd) 包括接口的 comment,verify 等信息都传进去处理 |
能跑吗?我给B站风控了... |
算了不测了,我风控前好像能跑,发了 |
你太着急了 bilibili-api/bilibili_api/data/api/credential.json Lines 1 to 7 in 5f1d82b
这种库里本来就有的东西不应该重复添加 提交之前先全局搜索下啊 |
明天吧,没去搜 |
有没有定论了,WBI多久更新一次 |
我今天刚跑了,貌似还不行,还是一直卡着,奇怪的是没有抛出异常 |
@Drelf2018 参数要排序,我忘了xd,能改改吗?在学校我没法整 |
#301 唉,重写 |
C#示例 private string _wbiString;
private DateTime _wbiTime;
private async Task<string> WbiKey(Dictionary<string, string> param) {
if (_wbiString == null || _wbiTime.AddHours(1) < DateTime.Now || _wbiTime.Day != DateTime.Now.Day) {
var info = await _statefulClient.GetStringAsync($"https://api.bilibili.com/x/web-interface/nav");
Logger.LogTrace(info);
var json = JObject.Parse(info);
var imgUrl = json["data"]!["wbi_img"]!["img_url"]!.Value<string>();
var subUrl = json["data"]!["wbi_img"]!["sub_url"]!.Value<string>();
var img = imgUrl.Split("/")[^1].Split(".")[0];
var sub = subUrl.Split("/")[^1].Split(".")[0];
var ae = img + sub;
Logger.LogTrace(ae);
var oe = new[] {
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42,
19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25,
54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52
};
var le = oe.Aggregate("", (s, b) => s + ae[b]);
_wbiString = le[..32];
_wbiTime = DateTime.Now;
}
var wts = DateTimeOffset.Now.ToUnixTimeSeconds();
param["wts"] = wts.ToString();
var str = string.Join("&",
param.ToImmutableSortedDictionary(StringComparer.Ordinal).Select(a => $"{a.Key}={a.Value}"));
Logger.LogTrace(str);
param["w_rid"] = Convert.ToHexString(MD5.HashData(Encoding.UTF8.GetBytes(str + _wbiString))).ToLower();
return string.Join("&", param.Select(a => $"{a.Key}={a.Value}"));
} |
这是py库。。。 |
基本上都是来找api找用例的,搬到不同语言用很正常,这里也算是这个问题的门户了 |
建议去 https://github.com/SocialSisterYi/bilibili-API-collect |
接 #289
部分接口不带鉴权参数的话可能有较高限制,已经影响使用
此 issue 汇总出问题的接口,并扒拉如何获取鉴权参数
The text was updated successfully, but these errors were encountered: