Files
RSSHub/lib/routes/qzcea/index.js
T
2020-09-20 21:40:00 +01:00

53 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
ctx.params.caty = ctx.params.caty || '1';
const rootUrl = 'http://www.qzcea.org';
const currentUrl = `${rootUrl}/usernewscatname_nc${ctx.params.caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('a.news-more').remove();
const list = $('li.clearfix div.news-right a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
pubDate: new Date(item.next().text().replace('时间 :', '') + ' GMT+8').toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('div.newm').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('title').text()} - 泉州市跨境电子商务协会`,
link: currentUrl,
item: items,
};
};