Files
RSSHub/lib/v2/nbd/article.js
Ethan Shen 0f503e55e0 fix(route): 每经网分类 (#7998)
* fix(route): 每经网分类

* refactor: migrate to v2

Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
2022-02-23 21:11:16 +08:00

51 lines
1.6 KiB
JavaScript

const cheerio = require('cheerio');
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const url = 'https://www.nbd.com.cn/columns/332';
const response = await got({
method: 'get',
url,
headers: {
Referer: 'https://www.nbd.com.cn',
},
});
const $ = cheerio.load(response.data);
const $list = $('li.u-news-title').slice(0, 15).get();
const description = $('head title').text().trim();
const resultItem = await Promise.all(
$list.map(async (item) => {
const title = $(item).find('a').text().trim();
const itemUrl = 'https:' + $(item).find('a').attr('href');
const single = await ctx.cache.tryGet(itemUrl, async () => {
const detail = await got({
method: 'get',
url: itemUrl,
headers: {
Referer: 'https://www.nbd.com.cn',
},
});
const $ = cheerio.load(detail.data);
return {
title,
link: itemUrl,
pubDate: timezone(parseDate(detail.data.match(/"pubDate": "(.*)"/)[1]), +8),
description: $('div.g-article').html(),
};
});
return single;
})
);
ctx.state.data = {
title: '重磅原创-每经网',
link: url,
item: resultItem,
description,
};
};