diff --git a/docs/journal.md b/docs/journal.md index 6e162cd4c..42ada50ca 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -517,4 +517,8 @@ You can get all short name of a journal from ### 作者期刊文献 - +::: tip 注意 +可能仅限中国大陆服务器访问,以实际情况为准。 +::: + + diff --git a/lib/v2/cnki/author.js b/lib/v2/cnki/author.js index dd6f70e37..2bdae4189 100644 --- a/lib/v2/cnki/author.js +++ b/lib/v2/cnki/author.js @@ -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, }; }; diff --git a/lib/v2/cnki/maintainer.js b/lib/v2/cnki/maintainer.js index 5bf0a3e28..e4e2b0a06 100644 --- a/lib/v2/cnki/maintainer.js +++ b/lib/v2/cnki/maintainer.js @@ -1,5 +1,5 @@ module.exports = { '/journals/:name': ['Fatpandac'], '/journals/debut/:name': ['Fatpandac'], - '/author/:code': ['harveyqiu'], + '/author/:code': ['harveyqiu', 'Derekmini'], };