From 9dd63f19ffb5bd0df91a55eb3b5fc77446bea925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Mon, 15 Oct 2018 16:26:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=85=AC=E4=BC=97=E5=B9=B3=E5=8F=B0-=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E6=A0=8F=E7=9B=AE=20(#895)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现 #883 - 没找到比较合适的分类,暂时先放到`程序更新`下面 - 由于正文内容是放在 `window.wxCgi` 中,输出的话需要出动 `puppeteer` 来搞,感觉意义不太大而且资源消耗也大,所以暂时未输出正文内容。后续如有需要再添加(其实用正则去匹配也不是不行(光速逃 - 最后有个疑问点:爬取到的链接中有这样的`https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11531387046zmIME&version=&lang=zh_CN`,中间带有`&`这类特殊符号,试了下发现输出为 `json` 格式时会转义掉变成这样`https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&announce_id=11531387046zmIME&version=&lang=zh_CN`,是无法直接使用了,好奇下这是个 bug 还是说设计如此(feature)?(还没来得及看这部分的处理逻辑 --- docs/README.md | 4 ++++ router.js | 1 + routes/wechat/announce.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 routes/wechat/announce.js diff --git a/docs/README.md b/docs/README.md index 2873a2478..11845a78e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -937,6 +937,10 @@ GitHub 官方也提供了一些 RSS: +### 微信公众平台 + + + ## 大学通知 ### 上海海事大学 diff --git a/router.js b/router.js index 54a67c28d..4145de3c7 100644 --- a/router.js +++ b/router.js @@ -451,6 +451,7 @@ router.get('/hopper/:lowestOnly/:from/:to?', require('./routes/hopper/index')); // wechat router.get('/wechat/wasi/:id', require('./routes/wechat/wasi')); +router.get('/wechat/announce', require('./routes/wechat/announce')); // 马蜂窝 router.get('/mafengwo/note/:type', require('./routes/mafengwo/note')); diff --git a/routes/wechat/announce.js b/routes/wechat/announce.js new file mode 100644 index 000000000..e4968e25b --- /dev/null +++ b/routes/wechat/announce.js @@ -0,0 +1,32 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { data: htmlString } = await axios({ + method: 'get', + url: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN', + }); + + const $ = cheerio.load(htmlString); + const announceList = []; + + $('.mp_news_list > .mp_news_item').each(function() { + const $item = $(this); + const $link = $item.find('a'); + const time = $item.find('.read_more').text(); + const title = $item.find('strong').text(); + + announceList.push({ + title: `${time} ${title}`, + link: `https://mp.weixin.qq.com${$link.attr('href')}`, + description: title, + pubDate: new Date(time).toUTCString(), + }); + }); + + ctx.state.data = { + title: '微信公众平台-系统公告栏目', + link: 'https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncementlist&lang=zh_CN&token=', + item: announceList, + }; +};