const got = require('got'); const timeout = 15000; const push_config = { // 官方文档:http://www.pushplus.plus/ PUSH_PLUS_TOKEN: '79e01a66036642e5969d52a5952b5cb7', // push+ 微信推送的用户令牌 PUSH_PLUS_USER: '', // push+ 微信推送的群组编码 }; const $ = { post: (params, callback) => { const { url, ...others } = params; got.post(url, others).then( (res) => { let body = res.body; try { body = JSON.parse(body); } catch (error) {} callback(null, res, body); }, (err) => { callback(err?.response?.body || err); } ); }, get: (params, callback) => { const { url, ...others } = params; got.get(url, others).then( (res) => { let body = res.body; try { body = JSON.parse(body); } catch (error) {} callback(null, res, body); }, (err) => { callback(err?.response?.body || err); } ); }, logErr: console.log, }; function pushPlusNotify(text, desp) { return new Promise((resolve) => { const { PUSH_PLUS_TOKEN, PUSH_PLUS_USER } = push_config; if (PUSH_PLUS_TOKEN) { desp = desp.replace(/[\n\r]/g, '
'); // 默认为html, 不支持plaintext const body = { token: `${PUSH_PLUS_TOKEN}`, title: `${text}`, content: `${desp}`, topic: `${PUSH_PLUS_USER}`, }; const options = { url: `https://www.pushplus.plus/send`, body: JSON.stringify(body), headers: { 'Content-Type': ' application/json', }, timeout, }; $.post(options, (err, resp, data) => { try { if (err) { console.log(`Push+ 发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息失败😞\n`, err); } else { if (data.code === 200) { console.log(`Push+ 发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息完成🎉\n`); } else { console.log( `Push+ 发送${PUSH_PLUS_USER ? '一对多' : '一对一'}通知消息异常 ${data.msg}\n` ); } } } catch (e) { $.logErr(e, resp); } finally { resolve(data); } }); } else { resolve(); } }); } const myHeaders = new Headers(); { myHeaders.append('accept', '*/*'); myHeaders.append('accept-language', 'zh-CN,zh;q=0.9,en;q=0.8'); myHeaders.append('cache-control', 'no-cache'); myHeaders.append( 'cookie', '_zap=7edb0b8f-4fa8-4cd7-bf98-b8f2e9dcbcd0; d_c0=ABASThk1PRmPToqcNXh7N3rh6Mu45nX4o9A=|1726384289; __snaker__id=7NBKnwPEsBAdxz8d; q_c1=d113395419514540a767ec62034830a6|1726384298000|1726384298000; _xsrf=Jwz5KIY4sOEXIrQJdRBqeb85HkITEmxB; z_c0=2|1:0|10:1732283927|4:z_c0|80:MS4xTG9IdkJBQUFBQUFtQUFBQVlBSlZUYjFBSzJpN0RJQ1Jyd1g1MnJwWXZNc3VseWtDRFZ4TW13PT0=|238d6b33695d6cd1bf56b50cb3555cde8e1a3a87afa219c1225344f978daf06c; __zse_ck=003_bd5hGL6qo63IYx1eNEOaWWxhkWw2kiMrYzWnEG6W8A7Yu5DKbL83A0UynUIT3WX4oCsNqADFzbuit2v=02SB0bRRmjtj4hFcZGXrOGdH3oxT; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1732443034,1732445363,1732452758,1732454765; HMACCOUNT=1DBE09E566A8974A; tst=h; SESSIONID=vnasVQE6nzGl4dcWT2nwj9dcYraop9BSYpkR3Pzev1u; JOID=VFsWAUnYmKpyJ55BCtypPf0_r30Wq_bKAXXKBD2y5-0fE_4nXbKw6BEmm0ALQTCQ33vIvDLs45Gt1X8TndO-Yag=; osd=UVsdA07dmKFwIJtBAd6uOP00rXoTq_3IBnDKDz-14u0UEfkiXbmy7xQmkEIMRDCb3XzNvDnu5JSt3n0UmNO1Y68=; BEC=4589376d83fd47c9203681b16177ae43; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1732454832' ); myHeaders.append('pragma', 'no-cache'); myHeaders.append('priority', 'u=1, i'); myHeaders.append('referer', 'https://www.zhihu.com/hot'); myHeaders.append( 'sec-ch-ua', '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"' ); myHeaders.append('sec-ch-ua-mobile', '?0'); myHeaders.append('sec-ch-ua-platform', '"Windows"'); myHeaders.append('sec-fetch-dest', 'empty'); myHeaders.append('sec-fetch-mode', 'cors'); myHeaders.append('sec-fetch-site', 'same-origin'); myHeaders.append( 'user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' ); myHeaders.append('x-api-version', '3.0.76'); myHeaders.append('x-requested-with', 'fetch'); myHeaders.append('x-zse-93', '101_3_3.0'); myHeaders.append( 'x-zse-96', '2.0_BOXFNfcgRatluI1hu0MO6y8C/KlDRffzJ/b4DmjgdrQJaJVnkwCm185lL7lQLu0q' ); myHeaders.append( 'x-zst-81', '3_2.0aR_sn77yn6O92wOB8hPZnQr0EMYxc4f18wNBUgpTQ6nxERFZm0Y0-4Lm-h3_tufIwJS8gcxTgJS_AuPZNcXCTwxI78YxEM20s4PGDwN8gGcYAupMWufIeQuK7AFpS6O1vukyQ_R0rRnsyukMGvxBEqeCiRnxEL2ZZrxmDucmqhPXnXFMTAoTF6RhRuLPFLV0MCNK_gULWuoMYhLy1vO8kqo8Hgt_obN0lGc8HbumpDp9SLLL4qV8ErcTv7tpBw2YHcOCQ_e0eqw8cL3mEB3Yjho0nqHmfcLf-JOm9hcqbcxf8gS10CLCQ4wqrePLXJX9XhLf2LVMLvNMkut0jvLGS6L_P9p8hG39UcxBoi9_HqpsCqfzfXOOJXOyJCgX8w2MzDLq2BxCSvXL20YLJD3LqJx0JbOf6G2GUrXOiweVwBOVg9Y08_H_0D3mPJXfSwVLwqFMsccVzCoLeqL_PDLfbDC8JCOpCweCwrOC' ); } const requestOptions = { method: 'GET', headers: myHeaders, redirect: 'follow', }; const fs = require('fs'); function getcurrentDate() { return `${new Date().getFullYear()}-${ new Date().getMonth() + 1 }-${new Date().getDate()}-${new Date().getMinutes()}`; } class zhihu_hot { constructor({ shortTitle, title, popularity, link }) { this.shortTitle = shortTitle; this.title = title; this.popularity = popularity; this.link = link; } } const saveFile = `${new Date().getTime()}_zhihu_hot.json`; (async () => { console.log('fetching zhihu hot list...'); let zhihu_hot_list; await fetch( 'https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true', requestOptions ) .then((response) => response.text()) .then((result) => { let data = JSON.parse(result)?.data; zhihu_hot_list = data.map( (item) => new zhihu_hot({ shortTitle: item.target.title_area.text, title: item.target.excerpt_area.text, popularity: item.target.metrics_area.text, link: item.target.link.url, }) ); fs.writeFileSync(saveFile, JSON.stringify(zhihu_hot_list, null, 2)); }) .catch((error) => console.error(error)); if (!zhihu_hot_list) { await pushPlusNotify('知乎热榜更新失败', '请查看日志获取详细信息'); } function setDiv(item) { return `

${item.shortTitle}

热度:${item.popularity}

${item.title}

`; } let content = zhihu_hot_list.reduce( (accumulator, currentValue) => accumulator + setDiv(currentValue), '' ); let html = ` 展示 知乎 数据 ${content} `; await pushPlusNotify('知乎热榜已更新', `${getcurrentDate()} 知乎热榜已更新` + html); console.log('fetching zhihu hot list done!'); })();