fix(route): 修正知网作者最新发布的期刊文献 (#12415)

* fix(route): use new knowledge-api link

* fix(route): update to use original code

* implement the functionality of fetching abstract

* docs: add maintainer name

* format

* fix(route): use fixed url for author and papers

* add a notice about CNKI in the journal.md file.

---------

Co-authored-by: Harvey Qiu <qiushimao@hotmail.com>
This commit is contained in:
Derek
2023-05-23 15:04:23 +08:00
committed by GitHub
co-authored by Harvey Qiu
parent 0118cadd39
commit 3b751bc9b4
3 changed files with 43 additions and 27 deletions
+5 -1
View File
@@ -517,4 +517,8 @@ You can get all short name of a journal from <https://www.nature.com/siteindex>
### 作者期刊文献
<Route author="harveyqiu" example="/cnki/author/000042423923" path="/cnki/author/:code" :paramsDesc="['作者对应code,可以在网址中得到']"/>
::: tip 注意
可能仅限中国大陆服务器访问,以实际情况为准。
:::
<Route author="harveyqiu Derekmini" example="/cnki/author/000042423923" path="/cnki/author/:code" :paramsDesc="['作者对应code,可以在网址中得到']"/>
+37 -25
View File
@@ -1,45 +1,57 @@
const utils = require('./utils');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
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&';
const rootUrl = 'https://kns.cnki.net';
module.exports = async (ctx) => {
const { code } = ctx.params;
const authorPageUrl = `${authorPageRootUrl}code=${code}`;
const res = await got(authorPageUrl);
const authorInfoUrl = `${rootUrl}/kcms/detail/knetsearch.aspx?sfield=au&code=${code}`;
const res = await got(authorInfoUrl);
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 res2 = await got(`${rootUrl}/kns8/Detail`, {
searchParams: {
sdb: 'CAPJ',
sfield: '作者',
skey: authorName,
scode: code,
acode: code,
},
followRedirect: false
});
const authorPageUrl = res2.headers.location;
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 regex = /v=([^&]+)/;
const code2 = authorPageUrl.match(regex)[1];
const url = `${rootUrl}/restapi/knowledge-api/v1/experts/relations/resources?v=${code2}&sequence=PT&size=10&sort=desc&start=1&resource=CJFD`;
const res3 = await got(url, {headers: {Referer: authorPageUrl}});
const publications = res3.data.data.data;
const list = publications.map((publication) => {
const metadata = publication.metadata;
const {value: title = ''} = metadata.find((md) => md.name === 'TI') || {};
const {value: date = ''} = metadata.find((md) => md.name === 'PT') || {};
const {value: filename = ''} = metadata.find((md) => md.name === 'FN') || {};
return {
title,
link: `https://cnki.net/kcms/detail/detail.aspx?filename=${filename}&dbcode=CJFD`,
author: authorName,
pubDate: date
};
});
const items = await Promise.all(list.map((item) => ctx.cache.tryGet(item.link, () => utils.ProcessItem(item))));
ctx.state.data = {
title: `知网 ${authorName} ${companyName}`,
link: authorPageUrl,
link: authorInfoUrl,
item: items,
};
};
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = {
'/journals/:name': ['Fatpandac'],
'/journals/debut/:name': ['Fatpandac'],
'/author/:code': ['harveyqiu'],
'/author/:code': ['harveyqiu', 'Derekmini'],
};