feat: add 公众号Telegrame 频道来源 (#2205)

* feat: add 公众号Telegrame 频道来源

* 去掉全文抓取
This commit is contained in:
Chenyang Shi
2019-05-22 22:46:53 +08:00
committed by DIYgod
parent 77c9450311
commit 09e331988a
3 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const { data } = await axios.get(`https://t.me/s/${id}`);
const $ = cheerio.load(data);
const list = $('.tgme_widget_message_wrap');
const out = await Promise.all(
list
.map((index, item) => {
item = $(item);
const title = item.find('.tgme_widget_message_text > a:nth-child(2)').text();
const link = item.find('.tgme_widget_message_text > a:nth-child(2)').attr('href');
const pubDate = new Date(item.find('.tgme_widget_message_date time').attr('datetime')).toUTCString();
const description = item.find('.tgme_widget_message_text').html();
const single = {
title,
pubDate,
link,
description,
};
return single;
})
.get()
);
out.reverse();
ctx.state.data = {
title: $('.tgme_channel_info_header_title').text(),
link: `https://t.me/s/${id}`,
item: out,
};
};