feat: add gradCafe(一个比较流行的国外研究生录取结果通知) (#2035)

* add gradCafe(国外一个比较流行的研究生录取结果论坛)

* add gradCafe(国外一个比较流行的研究生录取结果论坛)
This commit is contained in:
Chenning Li
2019-05-03 23:26:04 +08:00
committed by DIYgod
parent c4335a5acc
commit e775632031
3 changed files with 58 additions and 0 deletions

View File

@@ -503,3 +503,8 @@ type 为 all 时category 参数不支持 cost 和 free
## 毕马威
<Route name="洞察" author="LogicJake" example="/kpmg/insights" path="/kpmg/insights" />
## gradCafe(一个比较流行的国外研究生录取结果通知)
<Route name="gradCafe result" author="liecn" example="/gradcafe/result" path="/gradcafe/result" />
<Route name="gradCafe result by key words" author="liecn" example="/gradcafe/result/computer" path="/gradcafe/result/:type" :paramsDesc="['按关键词进行搜索,如 computer']/>

View File

@@ -1302,4 +1302,8 @@ router.get('/kpmg/insights', require('./routes/kpmg/insights'));
// Saraba1st
router.get('/saraba1st/thread/:tid', require('./routes/saraba1st/thread'));
// gradcafe
router.get('/gradcafe/result/:type', require('./routes/gradcafe/result'));
router.get('/gradcafe/result', require('./routes/gradcafe/result'));
module.exports = router;

View File

@@ -0,0 +1,49 @@
const cheerio = require('cheerio');
const axios = require('../../utils/axios');
const url = 'https://www.thegradcafe.com/survey/';
module.exports = async (ctx) => {
const type = ctx.params.type;
const res = await axios.get(url, {
params: {
q: type,
},
});
const $ = cheerio.load(res.data);
const list = $('table.submission-table tbody tr');
const out = list
.slice(0, 10)
.map(function() {
const title = $(this)
.find('.tcol1 ')
.text();
const author = $(this)
.find('.tcol2')
.text();
const description =
$(this)
.find($('strong').parents('.tcol3'))
.text() +
' Note:' +
$(this)
.find('.tcol6')
.text();
const pubDate = $(this)
.find('.tcol5')
.text();
const item = {
title,
author,
description,
pubDate,
// note
};
return item;
})
.get();
ctx.state.data = {
title: 'gradCafe',
link: url,
item: out,
};
};