diff --git a/docs/other.md b/docs/other.md index d3e16aa445..c2ef839043 100644 --- a/docs/other.md +++ b/docs/other.md @@ -99,6 +99,14 @@ pageClass: routes +### 谷歌学术作者引用更新 + + + +路由中的参数 id,即用户谷歌学术引用页面 url 中的 id,如 https://scholar.google.com/citations?hl=zh-CN&user=mlmE4JMAAAAJ 中 user= 后的 mlmE4JMAAAAJ。 + + + ### Google Doodles diff --git a/lib/router.js b/lib/router.js index fa8783a7b0..eafd85ee76 100644 --- a/lib/router.js +++ b/lib/router.js @@ -460,6 +460,7 @@ router.get('/fir/update/:id', require('./routes/fir/update')); router.get('/nvidia/webdriverupdate', require('./routes/nvidia/webdriverupdate')); // Google +router.get('/google/citations/:id', require('./routes/google/citations')); router.get('/google/scholar/:query', require('./routes/google/scholar')); router.get('/google/doodles/:language?', require('./routes/google/doodles')); diff --git a/lib/routes/google/citations.js b/lib/routes/google/citations.js new file mode 100644 index 0000000000..49bc5354d0 --- /dev/null +++ b/lib/routes/google/citations.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + let description = `Google Scholar Citation Monitor: ${id};`; + const BASE_URL = `https://scholar.google.com`; + const url = `https://scholar.google.com/citations?user=${id}`; + + const response = await got({ + method: 'get', + url, + }); + + const $ = cheerio.load(response.data); + + const profile = $('#gsc_prf .gsc_prf_il') + .eq(0) + .text(); + const homePage = $('#gsc_prf_ivh a').attr('href'); + const name = $('#gsc_prf_in').text(); + description += `name: ${name}; profile: ${profile}; homePage: ${homePage}`; + + const list = $('#gsc_a_b .gsc_a_tr').get(); + + const out = list.map((item) => { + const $ = cheerio.load(item); + + let itemUrl = $('.gsc_a_t a').attr('data-href'); + itemUrl = BASE_URL + itemUrl; + + const author = $('.gsc_a_t div') + .eq(0) + .text(); + const publication = $('.gsc_a_t div') + .eq(1) + .text(); + return { + title: $('.gsc_a_t a').text(), + description: `Author: ${author}; Publication: ${publication}`, + link: itemUrl, + guid: itemUrl, + }; + }); + ctx.state.data = { + title: `Google Scholar Citation Monitor: ${id}`, + link: url, + description: description, + item: out, + }; +};