调整IT之家数据结构
This commit is contained in:
parent
f18f9d7cf9
commit
e555a8b4fd
@ -26,30 +26,32 @@ const replaceLink = (url) => {
|
|||||||
// 数据处理
|
// 数据处理
|
||||||
const getData = (data) => {
|
const getData = (data) => {
|
||||||
if (!data) return false;
|
if (!data) return false;
|
||||||
const dataList = {};
|
const dataList = [];
|
||||||
const $ = cheerio.load(data);
|
const $ = cheerio.load(data);
|
||||||
try {
|
try {
|
||||||
$(".rank-name").each(function () {
|
$(".rank-name").each(function () {
|
||||||
const type = $(this).data("rank-type");
|
const type = $(this).data("rank-type");
|
||||||
const newListHtml = $(this).next(".rank-box").html();
|
const newListHtml = $(this).next(".rank-box").html();
|
||||||
const newsList = cheerio
|
cheerio
|
||||||
.load(newListHtml)(".placeholder")
|
.load(newListHtml)(".placeholder")
|
||||||
.get()
|
.get()
|
||||||
.map((v) => {
|
.map((v) => {
|
||||||
return {
|
dataList.push({
|
||||||
title: $(v).find(".plc-title").text(),
|
title: $(v).find(".plc-title").text(),
|
||||||
img: $(v).find("img").attr("data-original"),
|
img: $(v).find("img").attr("data-original"),
|
||||||
time: $(v).find(".post-time").text(),
|
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")),
|
url: replaceLink($(v).find("a").attr("href")),
|
||||||
mobileUrl: $(v).find("a").attr("href"),
|
mobileUrl: $(v).find("a").attr("href"),
|
||||||
};
|
|
||||||
});
|
});
|
||||||
dataList[type] = {
|
});
|
||||||
name: $(this).text(),
|
// dataList[type] = {
|
||||||
total: newsList.length,
|
// name: $(this).text(),
|
||||||
list: newsList,
|
// total: newsList.length,
|
||||||
};
|
// list: newsList,
|
||||||
|
// };
|
||||||
});
|
});
|
||||||
return dataList;
|
return dataList;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user