主播流水記錄導(dǎo)出表格
①??打開(kāi)主播流水詳情頁(yè)面 流水頁(yè)面
② 按 F12 打開(kāi)控制臺(tái)

③ 在紅色區(qū)域內(nèi)復(fù)制粘貼以下代碼,然后回車。
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,
? ? ? ? ? ? ? ? "時(shí)間": item.time,
? ? ? ? ? ? ? ? "禮物": item.gift_name,
? ? ? ? ? ? ? ? "數(shù)量": item.gift_num,
? ? ? ? ? ? ? ? "金瓜子": item.gold,
? ? ? ? ? ? ? ? "銀瓜子": item.silver,
? ? ? ? ? ? ? ? "IOS金瓜子": item.ios_gold,
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? return list;
? ? }
}
const exportButton = document.createElement('button');
exportButton.innerText = "導(dǎo)出";
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);
//?
④ 然后在搜索按鈕后面會(huì)出現(xiàn)一個(gè)導(dǎo)出按鈕,在左邊選好時(shí)間后,點(diǎn)擊導(dǎo)出就可以導(dǎo)出當(dāng)天的禮物流水啦w。
