主播流水记录导出表格
① 打开主播流水详情页面 流水页面
② 按 F12 打开控制台

③ 在红色区域内复制粘贴以下代码,然后回车。
class GiftTableExport {
static async run(date) {
let objects = await GiftTableExport.getGiftList(date);
const table = GiftTableExport.buildTable(Object.keys(objects[0]), objects.map(v => Object.values(v)));
GiftTableExport.tableToExcel(table, date);
}
static buildTable(titleColumns, valueColumns) {
const table = document.createElement('table');
const titleTr = document.createElement('tr');
table.append(titleTr);
titleColumns.map(v => {
const th = document.createElement('th');
th.innerText = v;
titleTr.appendChild(th);
});
valueColumns.map(v => {
const valueTr = document.createElement('tr');
v.map(vv => {
const th = document.createElement('th');
th.innerText = vv;
valueTr.appendChild(th);
});
table.append(valueTr);
});
return table;
}
static tableToExcel(table, fileName) {
function base64(content) {
return window.btoa(unescape(encodeURIComponent(content)));
}
let excelContent = table.innerHTML; let excelFile = `<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='htt${'p://w'}ww.${'w3.o'}rg/TR${'/REC-ht'}ml40'>`;
excelFile += "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>";
excelFile += "<body><table>";
excelFile += excelContent;
excelFile += "</table></body>";
excelFile += "</html>";
let link = "data:application/vnd.ms-excel;base64," + base64(excelFile);
const a = document.createElement("a");
a.download = fileName + ".xlsx";
a.href = link;
a.click();
}
static async getGiftList(date, last_id = 0) {const res = await fetch(`http${'s:/'}/ap${'i.l'}ive.bilibil${'i.co'}m/xlive/revenue/v1/giftSt${'ream/get'}ReceivedGiftStreamNextList?limit=50&coin_type=0&begin_time=${date}&last_id=${last_id}`, {
"headers": { "accept": "application/json, text/plain, */*", "accept-language": "zh-CN,zh;q=0.9", "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"99\", \"Google Chrome\";v=\"99\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Windows\"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site" },
"referrer": `http${'s://l'}in${'k.b'}ilibil${'i.co'}m/p/center/ind${'ex?'}spm_id_fr${'om=333.10'}07.0.0`,
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
const result = await res.json();
let { has_more, list } = result.data;
if (has_more) {
const nextList = await GiftTableExport.getGiftList(date, [...list].pop().id);
list = list.concat(nextList);
}
list = list.map(item => {
return {
"UID": item.uid,
"昵称": item.uname,
"时间": item.time,
"礼物": item.gift_name,
"数量": item.gift_num,
"金瓜子": item.gold,
"银瓜子": item.silver,
"IOS金瓜子": item.ios_gold,
}
});
return list;
}
}
const exportButton = document.createElement('button');
exportButton.innerText = "导出";
exportButton.onclick = () => {
const date = document.body.querySelector('.el-date-editor.selector.date-selector.el-input.el-date-editor--date input').value;
GiftTableExport.run(date)
}
document.body.querySelector('.item.nickName').appendChild(exportButton);
//
④ 然后在搜索按钮后面会出现一个导出按钮,在左边选好时间后,点击导出就可以导出当天的礼物流水啦w。
