mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
const cheerio = require('cheerio');
|
|
const got = require('@/utils/got');
|
|
|
|
module.exports = async (ctx) => {
|
|
const url = `https://www.scientificamerican.com/podcast/60-second-science/`;
|
|
|
|
const res = await got.get(url);
|
|
const $ = cheerio.load(res.data);
|
|
const list = $('.underlined_text.t_small').get();
|
|
|
|
const out = await Promise.all(
|
|
list.map(async (item) => {
|
|
const $ = cheerio.load(item);
|
|
const title = $(item).attr('aria-label');
|
|
const address = $(item).attr('href');
|
|
const cache = await ctx.cache.get(address);
|
|
if (cache) {
|
|
return Promise.resolve(JSON.parse(cache));
|
|
}
|
|
const res = await got.get(address);
|
|
const capture = cheerio.load(res.data);
|
|
|
|
const tStr = '.article-header__divider > ul > li > span:nth-child(2)';
|
|
const time = capture(tStr).text();
|
|
const aStr = '.article-header__divider > ul > li > span:nth-child(1) > span';
|
|
const author = capture(aStr).text();
|
|
|
|
capture('.transcript__close').remove();
|
|
const intro = capture('.article-media__object').html() + '<br><br>';
|
|
const contents = intro + capture('.transcript__inner').html();
|
|
const single = {
|
|
title,
|
|
description: contents,
|
|
link: address,
|
|
guid: address,
|
|
author: author,
|
|
pubDate: new Date(time).toUTCString(),
|
|
};
|
|
ctx.cache.set(address, JSON.stringify(single));
|
|
return Promise.resolve(single);
|
|
})
|
|
);
|
|
ctx.state.data = {
|
|
title: 'Transcripts of SA 60-Second Science',
|
|
link: url,
|
|
item: out,
|
|
};
|
|
};
|