mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
Add(route): add cnki (#8877)
This commit is contained in:
@@ -306,3 +306,13 @@ _仅支持 Science 主刊_
|
||||
| bqym | xshd | tzgg |
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国知网
|
||||
|
||||
### 期刊
|
||||
|
||||
<Route author="Fatpandac" example="/cnki/journals/LKGP" path="/cnki/journals/:name" :paramsDesc="['期刊缩写,可以在网址中得到']"/>
|
||||
|
||||
### 网络首发
|
||||
|
||||
<Route author="Fatpandac" example="/cnki/journals/debut/LKGP" path="/cnki/journals/debut/:name" :paramsDesc="['期刊缩写,可以在网址中得到']"/>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
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 rootUrl = 'https://chn.oversea.cnki.net';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { name } = ctx.params;
|
||||
|
||||
const journalUrl = `${rootUrl}/knavi/JournalDetail?pcode=CjFD&pykm=${name}`;
|
||||
const title = await got.get(journalUrl).then((res) => cheerio.load(res.data)('head > title').text());
|
||||
|
||||
const outlineUrl = `${rootUrl}/knavi/JournalDetail/GetnfAllOutline`;
|
||||
const response = await got({
|
||||
method: 'post',
|
||||
url: outlineUrl,
|
||||
form: {
|
||||
pageIdx: '0',
|
||||
type: '2',
|
||||
pcode: 'CJFD',
|
||||
pykm: name,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('dd')
|
||||
.map((_, item) => ({
|
||||
title: $(item).find('span.name > a').text().trim(),
|
||||
link: `${rootUrl}/kcms/detail/${new URLSearchParams(new URL(`${rootUrl}/${$(item).find('span.name > a').attr('href')}`).search).get('url')}.html`,
|
||||
pubDate: parseDate($(item).find('span.company').text(), 'YYYY-MM-DD HH:mm:ss'),
|
||||
}))
|
||||
.get();
|
||||
|
||||
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;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${title} - 全网首发`,
|
||||
link: `https://navi.cnki.net/knavi/journals/${name}/detail`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
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 rootUrl = 'https://chn.oversea.cnki.net';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { name } = ctx.params;
|
||||
const journalUrl = `${rootUrl}/knavi/JournalDetail?pcode=CjFD&pykm=${name}`;
|
||||
const title = await got.get(journalUrl).then((res) => cheerio.load(res.data)('head > title').text());
|
||||
|
||||
const yaerListUrl = `${rootUrl}/knavi/JournalDetail/GetJournalYearList?pcode=CJFD&pykm=${name}&pIdx=0`;
|
||||
const journalsInfo = await got.get(yaerListUrl).then((res) => {
|
||||
const $ = cheerio.load(res.data);
|
||||
const date = $('dd').find('a').first().attr('id').replace('yq', '');
|
||||
const year = date.substring(0, 4);
|
||||
const issue = date.substring(4);
|
||||
|
||||
return {
|
||||
year,
|
||||
issue,
|
||||
date,
|
||||
};
|
||||
});
|
||||
|
||||
const papersUrl = `${rootUrl}/knavi/JournalDetail/GetArticleList?year=${journalsInfo.year}&issue=${journalsInfo.issue}&pykm=${name}&pageIdx=0&pcode=CjFD`;
|
||||
const list = await got.get(papersUrl).then((res) => {
|
||||
const $ = cheerio.load(res.data);
|
||||
const item = $('span.name')
|
||||
.map((_, item) => {
|
||||
const url = new URL(`${rootUrl}/${$(item).find('a').attr('href')}`);
|
||||
const urlParams = new URLSearchParams(url.search);
|
||||
|
||||
return {
|
||||
title: $(item).find('a').text().trim(),
|
||||
link: `${rootUrl}/kcms/detail/detail.aspx?dbcode=${urlParams.get('dbCode')}&filename=${urlParams.get('filename')}`,
|
||||
pubDate: parseDate(journalsInfo.date, 'YYYYMM'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
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;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: String(title),
|
||||
link: `https://navi.cnki.net/knavi/journals/${name}/detail`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
'/journals/:name': ['Fatpandac'],
|
||||
'/journals/debut/:name': ['Fatpandac'],
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
'cnki.net': {
|
||||
_name: '中国知网',
|
||||
navi: [
|
||||
{
|
||||
title: '期刊',
|
||||
docs: 'https://docs.rsshub.app/journal.html#zhong-guo-zhi-wang-qi-kan',
|
||||
source: ['/knavi/journals/:name/detail'],
|
||||
target: '/cnki/journals/:name',
|
||||
},
|
||||
{
|
||||
title: '网络首发',
|
||||
docs: 'https://docs.rsshub.app/journal.html#zhong-guo-zhi-wang-wang-luo-shou-fa',
|
||||
source: ['/knavi/journals/:name/detail'],
|
||||
target: '/cnki/journals/debut/:name',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/journals/:name', require('./journals'));
|
||||
router.get('/journals/debut/:name', require('./debut'));
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
<text>作者:{{ author }} </text>
|
||||
<br>
|
||||
<text>单位:{{ company }} </text>
|
||||
<br>
|
||||
<text>{{ content }}</text>
|
||||
Reference in New Issue
Block a user