获取阿b的表情

方法来自知乎:如何下载b站表情包? - 知乎 不太用知乎所以还是转到自己的网站吧。

1.在登录的状态下访问https://api.bilibili.com/x/emote/setting/panel?business=reply ,存储为emoji.json(蛮长的,需要等点时间)。 2.编写python脚本,保存为emoji.py在emoji.json目录下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
import os
from concurrent.futures import ThreadPoolExecutor
from functools import partial
from time import sleep

import requests
from tqdm import tqdm


def mkdir(path):
if os.path.exists(path) is not True:
os.makedirs(path)


def download_pic(url, path):
resp = requests.get(url)
with open(path, 'wb') as code:
code.write(resp.content)


def download_emoji(emoji, save_path):
emoji_name = emoji['text']
emoji_name = emoji_name[1:-1]
path = os.path.join(save_path, f'{emoji_name}.png')
download_pic(emoji['url'], path)


def download_package(package, path):
package_name = package['text']
save_path = os.path.join(path, package_name)
mkdir(save_path)
all_emote = set(map(lambda e: e['text'][1:-1], package['emote']))
downloaded_emote = set(map(lambda e: e[:-4], os.listdir(save_path)))
download_emote_name = all_emote - downloaded_emote
if len(download_emote_name) == 0:
return
going_to_download_emote = filter(lambda e: e['text'][1:-1] in download_emote_name, package['emote'])
with ThreadPoolExecutor() as executor:
executor.map(partial(download_emoji, save_path=save_path), going_to_download_emote)
sleep(3)


if __name__ == '__main__':
with open('emoji.json', 'r', encoding='utf-8') as fp:
emojis = json.load(fp)
emoji_packages = emojis['data']['all_packages']
package_path = 'bilibili_emoji'
bar = tqdm(emoji_packages)
for p in bar:
if p['text'] == '颜文字':
continue
bar.set_description(p['text'])
download_package(p, package_path)
3.打开shell(windows里面powershell和cmd应该都可以),使用 pip install 安装包。
1
2
pip install requests
pip install tqdm
4.运行脚本,shell移动到目录可以cd,可以shift右键“在此处打开powershell”,可以在文件管理器里输目录的地方输cmd或者powershell回车。
1
python emoji.py