feat: 公众号增加二十次幂输出 (#2654)

This commit is contained in:
sanmmmm
2019-07-20 12:54:32 +08:00
committed by DIYgod
parent f0901c1c89
commit 26d08ee047
3 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { id } = ctx.params;
const url = `https://www.ershicimi.com/a/${id}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const name = $('#wrapper > .yheader > .info-wrap .name').text();
const description = $('#wrapper .right > .Card .Profile-sideColumnItemValue').text();
const items = $('.weui_media_box')
.map((_, ele) => {
const $item = cheerio.load(ele);
return {
title: $item('.weui_media_title a').text(),
link: $item('.weui_media_title a').attr('href'),
pubDate: new Date($item('.weui_media_extra_info').attr('title')).toUTCString(),
};
})
.get();
ctx.state.data = {
title: `微信公众号 - ${name}`,
link: url,
description,
item: items,
};
};