feat(route): 增加知网作者最新发布的期刊文献 (#11269)

* add cnki author

* add maintainer

* update radar

* cheerio

* fix name

* fix doc

* update radar & fix author

* fix radar
This commit is contained in:
Harvey Qiu
2022-11-16 17:08:32 +08:00
committed by GitHub
parent 7521ef2232
commit dbc536683b
9 changed files with 89 additions and 25 deletions
+1 -1
View File
@@ -387,7 +387,7 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re
### 上市公司信息最新公告披露
<Route author="alienmao" example="/sse/disclosure/beginDate=2018-08-18&endDate=2020-08-25&productId=600696" path="/sse/disclosure/:query?" :paramsDesc="['筛选条件,见示例']" radar="1" rssbud="1"/>
<Route author="harveyqiu" example="/sse/disclosure/beginDate=2018-08-18&endDate=2020-08-25&productId=600696" path="/sse/disclosure/:query?" :paramsDesc="['筛选条件,见示例']" radar="1" rssbud="1"/>
### 可转换公司债券公告
+4
View File
@@ -383,3 +383,7 @@ You can get all short name of a journal from <https://www.nature.com/siteindex>
### 网络首发
<Route author="Fatpandac" example="/cnki/journals/debut/LKGP" path="/cnki/journals/debut/:name" :paramsDesc="['期刊缩写,可以在网址中得到']"/>
### 作者期刊文献
<Route author="harveyqiu" example="/cnki/author/000042423923" path="/cnki/author/:code" :paramsDesc="['作者对应code,可以在网址中得到']"/>
+45
View File
@@ -0,0 +1,45 @@
const utils = require('./utils');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const rootUrl = 'https://chn.oversea.cnki.net/kcms/detail/frame/knetlist.aspx?infotype=4&codetype=1&vl=&';
const authorPageRootUrl = 'https://kns.cnki.net/kcms/detail/knetsearch.aspx?sfield=au&';
module.exports = async (ctx) => {
const { code } = ctx.params;
const authorPageUrl = `${authorPageRootUrl}code=${code}`;
const res = await got(authorPageUrl);
const $ = cheerio.load(res.data);
const authorName = $('#showname').text();
const companyName = $('body > div.wrapper > div.main > div.container.full-screen > div > div:nth-child(3) > h3:nth-child(2) > span > a').text();
const url = `${rootUrl}code=${code}`;
const list = await got
.get(url, {
headers: {
Referer: authorPageUrl,
},
})
.then((res) => {
const $ = cheerio.load(res.data);
const list = $('.bignum')
.children()
.map((_, e) => ({
title: $(e).find('a').first().text().trim(),
link: 'https://chn.oversea.cnki.net' + $(e).find('a').first().attr('href'),
}))
.get();
return list;
});
const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => utils.ProcessItem(item))));
ctx.state.data = {
title: `知网 ${authorName} ${companyName}`,
link: authorPageUrl,
item: items,
};
};
+2 -23
View File
@@ -1,8 +1,7 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const { ProcessItem } = require('./utils');
const rootUrl = 'https://chn.oversea.cnki.net';
@@ -44,27 +43,7 @@ module.exports = async (ctx) => {
return item;
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got.get(item.link);
const $ = cheerio.load(detailResponse.data);
item.description = art(path.join(__dirname, 'templates/desc.art'), {
author: $('h3.author > span')
.map((_, item) => $(item).text())
.get()
.join(' '),
company: $('a.author')
.map((_, item) => $(item).text())
.get()
.join(' '),
content: $('div.row > span.abstract-text').parent().text(),
});
return item;
})
)
);
const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => ProcessItem(item))));
ctx.state.data = {
title: String(title),
+1
View File
@@ -1,4 +1,5 @@
module.exports = {
'/journals/:name': ['Fatpandac'],
'/journals/debut/:name': ['Fatpandac'],
'/author/:code': ['harveyqiu'],
};
+8
View File
@@ -15,5 +15,13 @@ module.exports = {
target: '/cnki/journals/debut/:name',
},
],
kns: [
{
title: '作者期刊文献',
docs: 'https://docs.rsshub.app/journal.html#zhong-guo-zhi-wang-zuo-zhe-qi-kan-wen-xian',
source: ['/kcms/detail/knetsearch.aspx', '/'],
target: (_, url) => `/cnki/author/${new URL(url).searchParams.get('code')}`,
},
],
},
};
+1
View File
@@ -1,4 +1,5 @@
module.exports = function (router) {
router.get('/journals/:name', require('./journals'));
router.get('/journals/debut/:name', require('./debut'));
router.get('/author/:code', require('./author'));
};
+26
View File
@@ -0,0 +1,26 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { art } = require('@/utils/render');
const path = require('path');
const ProcessItem = async (item) => {
const detailResponse = await got(item.link);
const $ = cheerio.load(detailResponse.data);
item.description = art(path.join(__dirname, 'templates/desc.art'), {
author: $('h3.author > span')
.map((_, item) => $(item).text())
.get()
.join(' '),
company: $('a.author')
.map((_, item) => $(item).text())
.get()
.join(' '),
content: $('div.row > span.abstract-text').parent().text(),
});
return item;
};
module.exports = {
ProcessItem,
};
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = {
'/convert/:query?': ['kt286'],
'/disclosure/:query?': ['alienmao'],
'/disclosure/:query?': ['harveyqiu'],
'/inquire': ['Jeason0228'],
'/lawandrules/:slug?': ['nczitzk'],
'/renewal': ['Jeason0228'],