mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): add 国家药品监督管理局医疗器械标准管理中心 (#10206)
* feat(route): add 国家药品监督管理局医疗器械标准管理中心 * fix: shorten the route * fix: bad urls * fix: only 1 puppeteer request
This commit is contained in:
@@ -231,6 +231,22 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## 国家药品监督管理局医疗器械标准管理中心
|
||||
|
||||
### 通用
|
||||
|
||||
<Route author="nczitzk" example="/gov/nifdc/bshff/ylqxbzhgl/qxggtzh" path="/gov/nifdc/:path+" :paramsDesc="['路径,默认为公告通告']" radar="1" rssbud="1" puppeteer="1">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
路径处填写对应页面 URL 中 `https://www.nifdc.gov.cn/nifdc/` 与 `/index.html` 之间的字段,下面是一个例子。
|
||||
|
||||
若订阅 [公告通告](https://www.nifdc.org.cn/nifdc/bshff/ylqxbzhgl/qxggtzh/index.html) 则将对应页面 URL <https://www.nifdc.org.cn/nifdc/bshff/ylqxbzhgl/qxggtzh/index.html> 中 `https://www.nifdc.org.cn/nifdc/` 和 `/index.html` 之间的字段 `bshff/ylqxbzhgl/qxggtzh` 作为路径填入。此时路由为 [`/gov/nifdc/bshff/ylqxbzhgl/qxggtzh`](https://rsshub.app/gov/nifdc/bshff/ylqxbzhgl/qxggtzh)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 国家药品审评网站
|
||||
|
||||
### 首页
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = {
|
||||
'/miit/zcjd': ['Yoge-Code'],
|
||||
'/moe/:type': ['Crawler995'],
|
||||
'/moj/aac/news/:type?': ['TonyRL'],
|
||||
'/nifdc/:path+': ['nczitzk'],
|
||||
'/nmpa/:path+': ['TonyRL'],
|
||||
'/nrta/news/:category?': ['yuxinliu-alex'],
|
||||
'/nsfc/news/:type?': ['Derekmini', 'nczitzk'],
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const params = ctx.path === '/nifdc' ? '/nifdc/bshff/ylqxbzhgl/qxggtzh' : ctx.path;
|
||||
|
||||
const rootUrl = 'https://www.nifdc.org.cn';
|
||||
const currentUrl = `${rootUrl}${params}/index.html`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('.list ul li a')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: /^http/.test(link) ? link : new URL(link, currentUrl).href,
|
||||
pubDate: parseDate(
|
||||
item
|
||||
.next()
|
||||
.text()
|
||||
.match(/\((.*)\)/)
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (/^https:\/\/www\.nmpa\.gov\.cn\//.test(item.link)) {
|
||||
const page = await browser.newPage();
|
||||
await page.setRequestInterception(true);
|
||||
|
||||
page.on('request', (request) => {
|
||||
request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort();
|
||||
});
|
||||
|
||||
await page.goto(item.link, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
await page.waitForSelector('.text');
|
||||
const html = await page.evaluate(() => document.documentElement.innerHTML);
|
||||
await page.close();
|
||||
|
||||
const content = cheerio.load(html);
|
||||
|
||||
item.description = content('.text').html();
|
||||
} else {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.text').html();
|
||||
item.pubDate = timezone(parseDate(content('meta[name="PubDate"]').attr('content')), +8);
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await browser.close();
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text().replace(/----/, ' - '),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -461,6 +461,17 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
'nifdc.gov.cn': {
|
||||
_name: '国家药品监督管理局医疗器械标准管理中心',
|
||||
'.': [
|
||||
{
|
||||
title: '通用',
|
||||
docs: 'https://docs.rsshub.app/government.html#guo-jia-yao-pin-jian-du-guan-li-ju-yi-liao-qi-xie-biao-zhun-guan-li-zhong-xin',
|
||||
source: ['/*path'],
|
||||
target: (params) => `/gov/nifdc/${params.path.replace('/index.html', '')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
'nmpa.gov.cn': {
|
||||
_name: '国家药品监督管理局',
|
||||
'.': [
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = function (router) {
|
||||
router.get('/miit/zcjd', require('./miit/zcjd'));
|
||||
router.get('/moe/:type', require('./moe/moe'));
|
||||
router.get('/moj/aac/news/:type?', require('./moj/aac/news'));
|
||||
router.get(/nifdc\/([\w/-]+)?/, require('./nifdc'));
|
||||
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
|
||||
router.get('/nrta/news/:category?', require('./nrta/news'));
|
||||
router.get('/nsfc/news/:type?', require('./nsfc'));
|
||||
|
||||
Reference in New Issue
Block a user