rsshub
Version:
Make RSS Great Again!
41 lines (34 loc) • 1.18 kB
JavaScript
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'http://www.zhonglun.com/zx/zlgd.html';
const ori_url = 'http://www.zhonglun.com';
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.zx_list ul li').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const sub_url = $('a').attr('href');
const itemUrl = ori_url + sub_url;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return JSON.parse(cache);
}
const responses = await got.get(itemUrl);
const $d = cheerio.load(responses.data);
const single = {
title: $d('.news_main .txt span').html(),
link: itemUrl,
description: $d('.news_main').html(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return single;
})
);
ctx.state.data = {
title: $('title').text(),
link: url,
item: out,
};
};