From 11b25aa87091307745a9efde9600a2ba59b32783 Mon Sep 17 00:00:00 2001 From: Just-Prog Date: Mon, 5 Aug 2024 09:51:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=94=E5=93=A9=E5=93=94=E5=93=A9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3:=20=E9=9A=8F=E6=9C=BA=E5=8C=96=20`api.bilibili.com`?= =?UTF-8?q?=20=E7=9B=B8=E5=85=B3=E4=B8=9A=E5=8A=A1=E5=9F=9F=E5=90=8D=20ins?= =?UTF-8?q?pired=20by=20nilaoda/BBDown#915?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bili/bili_api.py | 5 +++-- bili/bili_domain.py | 10 ++++++++++ bili/bili_wbi.py | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 bili/bili_domain.py diff --git a/bili/bili_api.py b/bili/bili_api.py index 385adb8..49db4f9 100644 --- a/bili/bili_api.py +++ b/bili/bili_api.py @@ -1,5 +1,6 @@ import requests from bili.bili_wbi import getWBI +from bili.bili_domain import randomDomain bili_headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36", @@ -207,7 +208,7 @@ def get_dynamic_list(self, host_mid, offset='') -> dict: 'host_mid': host_mid, 'offset': offset } - resp = requests.get('https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space', + resp = requests.get('https://'+randomDomain()+'/x/polymer/web-dynamic/v1/feed/space', headers=self.headers, params=params, cookies=self.cookies).json() if resp.get('code') == -352: raise Exception("哔哩哔哩接口风控") @@ -221,7 +222,7 @@ def get_user_info(self, uid): :return: 从哔哩哔哩获取的源数据,详见 https://socialsisteryi.github.io/bilibili-API-collect/docs/user/info.html """ params = getWBI({'mid': uid}) - resp = requests.get('https://api.bilibili.com/x/space/wbi/acc/info', params=params, + resp = requests.get('https://'+randomDomain()+'/x/space/wbi/acc/info', params=params, headers=self.headers, cookies=self.cookies).json() if resp.get("code") != 0: raise Exception(resp.get("message")) diff --git a/bili/bili_domain.py b/bili/bili_domain.py new file mode 100644 index 0000000..df532b7 --- /dev/null +++ b/bili/bili_domain.py @@ -0,0 +1,10 @@ +import random + +def randomDomain(): + bili_api = [ + 'api.bilibili.com', + 'api.biliapi.com', + 'api.biliapi.net' + ] + base_url = random.choice(bili_api) + return base_url \ No newline at end of file diff --git a/bili/bili_wbi.py b/bili/bili_wbi.py index b2b7e2f..f86f1b0 100644 --- a/bili/bili_wbi.py +++ b/bili/bili_wbi.py @@ -3,6 +3,7 @@ import urllib.parse import time import requests +from bili.bili_domain import randomDomain mixinKeyEncTab = [ 46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, @@ -50,7 +51,7 @@ def getWbiKeys() -> tuple[str, str]: 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', 'Referer': 'https://www.bilibili.com/' } - resp = requests.get('https://api.bilibili.com/x/web-interface/nav', headers=headers) + resp = requests.get('https://'+randomDomain()+'/x/web-interface/nav', headers=headers) resp.raise_for_status() json_content = resp.json() img_url: str = json_content['data']['wbi_img']['img_url']