fix(route): NPC URLs have been changed (#13449)
* fix(route): NPC URLs have been changed * fix relative URLs * refactor: migrate to v2 ---------
This commit is contained in:
parent
996e432692
commit
d424adf021
|
|
@ -2064,7 +2064,7 @@ router.get('/nobelprize/:caty?', lazyloadRouteHandler('./routes/nobelprize/index
|
|||
router.get('/gov/taiwan/mnd', lazyloadRouteHandler('./routes/gov/taiwan/mnd'));
|
||||
|
||||
// 中国人大网
|
||||
router.get('/npc/:caty', lazyloadRouteHandler('./routes/npc/index'));
|
||||
// router.get('/npc/:caty', lazyloadRouteHandler('./routes/npc/index'));
|
||||
|
||||
// 高科技行业门户
|
||||
router.get('/ofweek/news', lazyloadRouteHandler('./routes/ofweek/news'));
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { caty } = ctx.params;
|
||||
// 主页
|
||||
const response = await got(`http://www.npc.gov.cn/npc/${caty}/list.shtml`);
|
||||
const data = response.body;
|
||||
const $ = cheerio.load(data, { decodeEntities: false });
|
||||
const title = $('title').text();
|
||||
// 获取每条的链接
|
||||
const links = $('.clist a')
|
||||
.map((index, item) => [$(item).attr('href')])
|
||||
.get();
|
||||
// 获取标题、日期、内容
|
||||
const list = await Promise.all(
|
||||
links.map(async (link) => {
|
||||
const response = await got(`http://www.npc.gov.cn${link}`);
|
||||
const data = response.body;
|
||||
const $ = cheerio.load(data, { decodeEntities: false });
|
||||
const title = $('title').text().replace('_中国人大网', '');
|
||||
const time = $('span.fr').text();
|
||||
const description = $('#Zoom p')
|
||||
.map((index, item) => $.html(item))
|
||||
.get()
|
||||
.join('');
|
||||
return Promise.resolve([title, link, time, description]);
|
||||
})
|
||||
);
|
||||
// 整合
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: `http://www.npc.gov.cn/npc/${caty}/list.shtml`,
|
||||
description: title,
|
||||
item: list.map((item) => ({
|
||||
title: item[0],
|
||||
link: `http://www.npc.gov.cn${item[1]}`,
|
||||
pubDate: new Date(Date.parse(item[2].replace(/[年月日]/g, '/'))).toUTCString(),
|
||||
description: item[3],
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
@ -35,6 +35,7 @@ module.exports = {
|
|||
'/nifdc/:path+': ['nczitzk'],
|
||||
'/nmpa/:path+': ['TonyRL'],
|
||||
'/nopss/:path+': ['nczitzk'],
|
||||
'/npc/:caty': ['233yeee'],
|
||||
'/nrta/news/:category?': ['yuxinliu-alex'],
|
||||
'/nrta/dsj/:category?': ['nczitzk'],
|
||||
'/nsfc/news/:type?': ['Derekmini', 'nczitzk'],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { caty } = ctx.params;
|
||||
// 主页
|
||||
const baseurl = `http://www.npc.gov.cn/npc/c2/${caty}/`;
|
||||
const response = await got(baseurl);
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const title = $('title').text();
|
||||
// 获取每条的链接
|
||||
const links = $('.clist a')
|
||||
.toArray()
|
||||
.map((item) => new URL($(item).attr('href'), baseurl).href);
|
||||
// 获取标题、日期、内容
|
||||
const items = await Promise.all(
|
||||
links.map((link) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
const response = await got(link);
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const title = $('title').text().replace('_中国人大网', '');
|
||||
const time = $('script:contains("fbrq")')
|
||||
.text()
|
||||
.match(/fbrq = "(.*?)"/)[1];
|
||||
const description = $('#Zoom').html();
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
pubDate: timezone(parseDate(time, 'YYYY年MM月DD日 HH:mm'), +8),
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
// 整合
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: baseurl,
|
||||
description: title,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -836,6 +836,17 @@ module.exports = {
|
|||
},
|
||||
],
|
||||
},
|
||||
'npc.gov.cn': {
|
||||
_name: '中国人大网',
|
||||
'.': [
|
||||
{
|
||||
title: '通用',
|
||||
docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ren-da-wang',
|
||||
source: ['/npc/c2/:caty'],
|
||||
target: '/gov/npc/:caty',
|
||||
},
|
||||
],
|
||||
},
|
||||
'nrta.gov.cn': {
|
||||
_name: '国家广播电视总局',
|
||||
'.': [
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ module.exports = function (router) {
|
|||
router.get(/nifdc\/([\w/-]+)?/, require('./nifdc'));
|
||||
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
|
||||
router.get(/nopss(\/[\w/-]+)?/, require('./nopss'));
|
||||
router.get('/npc/:caty', require('./npc/index'));
|
||||
router.get('/nrta/news/:category?', require('./nrta/news'));
|
||||
router.get('/nrta/dsj/:category?', require('./nrta/dsj'));
|
||||
router.get(/nsfc(\/[\w-/]+)?/, require('./nsfc'));
|
||||
|
|
|
|||
|
|
@ -1244,7 +1244,9 @@ Language
|
|||
|
||||
## 中国人大网 {#zhong-guo-ren-da-wang}
|
||||
|
||||
<Route author="233yeee" example="/npc/c183" path="/npc/:caty" paramsDesc={['分类名,支持形如 `http://www.npc.gov.cn/npc/*/list.shtml` 的网站,传入 npc 之后的参数']}>
|
||||
### 通用 {#zhong-guo-ren-da-wang-tong-yong}
|
||||
|
||||
<Route author="233yeee" example="/gov/npc/c183" path="/gov/npc/:caty" paramsDesc={['分类名,支持形如 `http://www.npc.gov.cn/npc/c2/*/` 的网站,传入 npc 之后的参数']}>
|
||||
|
||||
| 立法 | 监督 | 代表 | 理论 | 权威发布 | 滚动新闻 |
|
||||
| ---- | ---- | ---- | ---- | -------- | -------- |
|
||||
|
|
|
|||
Loading…
Reference in New Issue