fix(route): researchgate (#11429)
This commit is contained in:
parent
cd0b88f1c2
commit
8ed999f1b5
|
|
@ -581,12 +581,6 @@ Compared to the official one, this feed:
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## Research Gate
|
||||
|
||||
### Publications
|
||||
|
||||
<RouteEn author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['Username, can be found in URL']"/>
|
||||
|
||||
## RSS3
|
||||
|
||||
### Blog
|
||||
|
|
|
|||
|
|
@ -108,6 +108,12 @@ pageClass: routes
|
|||
|
||||
<RouteEn author="OrangeEd1t" example="/orcid/0000-0002-4731-9700" path="/orcid/:id" :paramsDesc="['Open Researcher and Contributor ID']"/>
|
||||
|
||||
## ResearchGate
|
||||
|
||||
### Publications
|
||||
|
||||
<RouteEn author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['Username, can be found in URL']" puppeteer="1" anticrawler="1"/>
|
||||
|
||||
## X-MOL
|
||||
|
||||
### News
|
||||
|
|
|
|||
|
|
@ -1187,12 +1187,6 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
|||
|
||||
</Route>
|
||||
|
||||
## Research Gate
|
||||
|
||||
### Publications
|
||||
|
||||
<Route author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['用户名,可在用户页地址栏中找到']"/>
|
||||
|
||||
## RSS3
|
||||
|
||||
### Blog
|
||||
|
|
|
|||
|
|
@ -234,6 +234,12 @@ path="/ctfhub/upcoming/:limit?"
|
|||
|
||||
</Route>
|
||||
|
||||
## ResearchGate
|
||||
|
||||
### Publications
|
||||
|
||||
<Route author="nczitzk" example="/researchgate/publications/Somsak-Panha" path="/researchgate/publications/:username" :paramsDesc="['用户名,可在用户页地址栏中找到']" puppeteer="1" anticrawler="1"/>
|
||||
|
||||
## X-MOL 平台
|
||||
|
||||
### 新闻
|
||||
|
|
|
|||
|
|
@ -4028,7 +4028,7 @@ router.get('/sbs/chinese/:category?/:id?/:dialect?/:language?', lazyloadRouteHan
|
|||
// router.get('/asiantolick/:category?/:keyword?', lazyloadRouteHandler('./routes/asiantolick'));
|
||||
|
||||
// Research Gate
|
||||
router.get('/researchgate/publications/:id', lazyloadRouteHandler('./routes/researchgate/publications'));
|
||||
// router.get('/researchgate/publications/:id', lazyloadRouteHandler('./routes/researchgate/publications'));
|
||||
|
||||
// QuestMobile
|
||||
router.get('/questmobile/report/:category?/:label?', lazyloadRouteHandler('./routes/questmobile/report'));
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const rootUrl = 'https://www.researchgate.net';
|
||||
const currentUrl = `${rootUrl}/profile/${id}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('div[itemprop="headline"] a')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.doi = content('meta[property="citation_doi"]').attr('content');
|
||||
item.pubDate = Date.parse(content('meta[property="citation_publication_date"]').attr('content'));
|
||||
|
||||
const authors = [];
|
||||
|
||||
content('meta[property="citation_author"]').each(function () {
|
||||
authors.push(content(this).attr('content'));
|
||||
});
|
||||
|
||||
item.author = authors.join(', ');
|
||||
|
||||
item.description = content('div[itemprop="description"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('meta[property="profile:username"]').attr('content')}'s Publications - ResearchGate`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/publications/:username': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const rootUrl = 'https://www.researchgate.net';
|
||||
const currentUrl = `${rootUrl}/profile/${id}`;
|
||||
const browser = await require('@/utils/puppeteer')();
|
||||
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(currentUrl);
|
||||
const response = await page.evaluate(() => document.documentElement.innerHTML);
|
||||
await page.close();
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const list = $('div[itemprop="headline"] a')
|
||||
.toArray()
|
||||
.slice(0, ctx.query.limit ? Number(ctx.query.limit) : 15)
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
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);
|
||||
const detailResponse = await page.evaluate(() => document.documentElement.innerHTML);
|
||||
await page.close();
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
item.doi = content('meta[property="citation_doi"]').attr('content');
|
||||
item.pubDate = parseDate(content('meta[property="citation_publication_date"]').attr('content'));
|
||||
|
||||
const authors = [];
|
||||
|
||||
content('meta[property="citation_author"]').each(function () {
|
||||
authors.push(content(this).attr('content'));
|
||||
});
|
||||
|
||||
item.author = authors.join(', ');
|
||||
|
||||
item.description = content('div[itemprop="description"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
await browser.close();
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('meta[property="profile:username"]').attr('content')}'s Publications - ResearchGate`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'researchgate.net': {
|
||||
_name: 'ResearchGate',
|
||||
'.': [
|
||||
{
|
||||
title: 'Publications',
|
||||
docs: 'https://docs.rsshub.app/study.html#researchgate',
|
||||
source: ['/profile/:username'],
|
||||
target: '/researchgate/publications/:username',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/publications/:id', require('./publications'));
|
||||
};
|
||||
Loading…
Reference in New Issue