diff --git a/README.md b/README.md index 937de6e8b..b25ddbb63 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 资讯 - All the Flight Deals - 特价机票 Flight deals +- Google + - 谷歌学术关键词更新 diff --git a/docs/README.md b/docs/README.md index 9a7459ed4..1b77f7577 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 + +### 谷歌学术关键词更新 + +举例: [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)。 diff --git a/router.js b/router.js index 3e064bf56..5815e7e4e 100755 --- a/router.js +++ b/router.js @@ -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; diff --git a/routes/google/scholar.js b/routes/google/scholar.js new file mode 100644 index 000000000..8fbe02a15 --- /dev/null +++ b/routes/google/scholar.js @@ -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, + }; +};