From 37c25b42dc9932881e3bc9e8271cdd1ca6823414 Mon Sep 17 00:00:00 2001 From: Huang Kan Date: Mon, 8 Jul 2019 21:58:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B0=B7=E6=AD=8C?= =?UTF-8?q?=E5=AD=A6=E6=9C=AF=E5=BC=95=E7=94=A8=E2=99=A5=EF=B8=8F=20(#2565?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加路由動漫狂|add router for (https://www.cartoonmad.com) * change carriages to lf * use prettier * add info to docs/readme.md * adding route for google scholar citation * formation * remove promise all --- docs/other.md | 8 ++++++ lib/router.js | 1 + lib/routes/google/citations.js | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 lib/routes/google/citations.js 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, + }; +};