mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-30 16:55:08 +08:00
feat: add 中华人民共和国商务部 (#2745)
This commit is contained in:
@@ -188,6 +188,12 @@ pageClass: routes
|
||||
| 贝尔法斯特 | `/embassy/uk/belfast` |
|
||||
| 曼彻斯特 | `/embassy/uk/manchester` |
|
||||
|
||||
## 中华人民共和国商务部
|
||||
|
||||
### 政务公开
|
||||
|
||||
<Route author="LogicJake" example="/mofcom/article/b" path="/mofcom/article/:suffix" :paramsDesc="['支持形如`http://www.mofcom.gov.cn/article/*`的网站,传入 article 之后的后缀']" />
|
||||
|
||||
## 中华人民共和国生态环境部
|
||||
|
||||
### 公示
|
||||
|
||||
@@ -1591,4 +1591,7 @@ router.get('/aliyun/database_month', require('./routes/aliyun/database_month'));
|
||||
// 礼物说
|
||||
router.get('/liwushuo/index', require('./routes/liwushuo/index.js'));
|
||||
|
||||
// 中华人民共和国商务部
|
||||
router.get('/mofcom/article/:suffix', require('./routes/mofcom/article'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const { resolve } = require('url');
|
||||
|
||||
const host = 'http://www.mofcom.gov.cn';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const suffix = ctx.params.suffix;
|
||||
const url = resolve('http://www.mofcom.gov.cn/article/', suffix);
|
||||
const res = await got.get(url);
|
||||
const $ = cheerio.load(res.data);
|
||||
const title = $('head > title').text();
|
||||
const list = $('.u-newsList01.f-mt10 li').get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const title = $('a').attr('title');
|
||||
const sub_url = $('a').attr('href');
|
||||
const itemUrl = resolve(host, sub_url);
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const responses = await got.get(itemUrl);
|
||||
const $d = cheerio.load(responses.data);
|
||||
|
||||
const single = {
|
||||
title,
|
||||
link: itemUrl,
|
||||
description: $d('.artCon').html(),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: url,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user