From e555a8b4fda4eac697ca376648be48800579bbc0 Mon Sep 17 00:00:00 2001 From: imsyy Date: Fri, 17 Mar 2023 14:09:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4IT=E4=B9=8B=E5=AE=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/ithome.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/routes/ithome.js b/routes/ithome.js index 3c1d7b1..f081a72 100644 --- a/routes/ithome.js +++ b/routes/ithome.js @@ -26,30 +26,32 @@ const replaceLink = (url) => { // 数据处理 const getData = (data) => { if (!data) return false; - const dataList = {}; + const dataList = []; const $ = cheerio.load(data); try { $(".rank-name").each(function () { const type = $(this).data("rank-type"); const newListHtml = $(this).next(".rank-box").html(); - const newsList = cheerio + cheerio .load(newListHtml)(".placeholder") .get() .map((v) => { - return { + dataList.push({ title: $(v).find(".plc-title").text(), img: $(v).find("img").attr("data-original"), time: $(v).find(".post-time").text(), - hot: $(v).find(".review-num").text(), + type: $(this).text(), + typeName: type, + hot: Number($(v).find(".review-num").text().replace(/\D/g, "")), url: replaceLink($(v).find("a").attr("href")), mobileUrl: $(v).find("a").attr("href"), - }; + }); }); - dataList[type] = { - name: $(this).text(), - total: newsList.length, - list: newsList, - }; + // dataList[type] = { + // name: $(this).text(), + // total: newsList.length, + // list: newsList, + // }; }); return dataList; } catch (error) {