Add Google Scholar closes #363 (#463)

This commit is contained in:
Henry Wang
2018-08-14 07:25:58 +01:00
committed by DIYgod
parent 1cf5f3d862
commit e676b0892e
4 changed files with 76 additions and 0 deletions

View File

@@ -227,6 +227,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 资讯
- All the Flight Deals
- 特价机票 Flight deals
- Google
- 谷歌学术关键词更新
</details>

View File

@@ -1826,3 +1826,16 @@ locations: 始发地,由「国家,参见 ISO 3166-1 国家代码」和「城
ISO 3166-1 国家代码列表请参见 [https://en.wikipedia.org/wiki/ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1)
nearby: 可选 0 或 1默认 0 为不包括,是否包括临近机场
## Google
### 谷歌学术关键词更新 <Author uid="HenryQW"/>
举例: [https://rsshub.app/google/scholar/data+visualizaton」](https://rsshub.app/google/scholar/data+visualizaton)
路由: `/google/scholar/:query`
参数query: 查询语句,支持「简单」和「高级」两种模式:
1. 简单模式例如「data visualizaton」[https://rsshub.app/google/scholar/data+visualizaton](https://rsshub.app/google/scholar/data+visualizaton)。
2. 高级模式,前往 [Google Scholar](https://scholar.google.com/schhp?hl=zh-cn&as_sdt=0,5),点击左上角,选择高级搜索并提交查询。此时 URL 应为:[https://scholar.google.com/scholar?as_q=data+visualizaton&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=zh-CN&as_sdt=0%2C5](https://scholar.google.com/scholar?as_q=data+visualizaton&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=zh-CN&as_sdt=0%2C5),复制`https://scholar.google.com/scholar?`后的所有语句作为本路由的查询参数。例子所对应的完整路由为[https://rsshub.app/google/scholar/as_q=data+visualizaton&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=zh-CN&as_sdt=0%2C5](https://rsshub.app/google/scholar/as_q=data+visualizaton&as_epq=&as_oq=&as_eq=&as_occt=any&as_sauthors=&as_publication=&as_ylo=2018&as_yhi=&hl=zh-CN&as_sdt=0%2C5)。

View File

@@ -415,4 +415,7 @@ router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));
// Fir
router.get('/fir/update/:id', require('./routes/fir/update'));
// Google
router.get('/google/scholar/:query', require('./routes/google/scholar'));
module.exports = router;

58
routes/google/scholar.js Normal file
View File

@@ -0,0 +1,58 @@
const axios = require('../../utils/axios');
const config = require('../../config');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let params = ctx.params.query;
let query = params;
let description = `Google Scholar Monitor Query: ${query}`;
if (params.indexOf('as_q=', 0) !== -1) {
const reg = /as_q=(.*?)&/g;
query = reg.exec(params)[1];
description = `Google Scholar Monitor Advanced Query: ${query}`;
} else {
params = 'q=' + params;
}
const url = `https://scholar.google.com/scholar?${params}`;
const response = await axios({
method: 'get',
url,
headers: {
'User-Agent': config.ua,
},
});
const $ = cheerio.load(response.data);
const list = $('#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri');
const out = [];
for (let i = 0; i < list.length; i++) {
const $ = cheerio.load(list[i]);
const itemUrl = $('h3 a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
out.push(JSON.parse(cache));
continue;
}
const single = {
title: $('h3 a').text(),
author: $('.gs_a').text(),
description: $('.gs_rs').text(),
link: itemUrl,
guid: itemUrl,
};
out.push(single);
}
ctx.state.data = {
title: `Google Scholar Monitor: ${query}`,
link: url,
description,
item: out,
};
};