diff --git a/docs/university.md b/docs/university.md index a4373c4928..1aa2fa31bd 100644 --- a/docs/university.md +++ b/docs/university.md @@ -3750,3 +3750,17 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 数据科学与计算机学院动态 + +### 粤港澳发展研究院 + + + +| 人才招聘 | 人才培养 | 新闻动态 | 通知公告 | 专家观点 | +| ---------- | ------------- | -------- | -------- | -------- | +| jobopening | personnelplan | news | notice | opinion | + +| 研究成果 | 研究论文 | 学术著作 | 形势政策 | +| -------- | -------- | -------- | -------- | +| results | papers | writings | policy | + + diff --git a/lib/v2/sysu/maintainer.js b/lib/v2/sysu/maintainer.js index defe196ad2..abb53ace8b 100644 --- a/lib/v2/sysu/maintainer.js +++ b/lib/v2/sysu/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/sysu/cse': ['Neutrino3316', 'MegrezZhu', 'nczitzk'], + '/ygafz/:type?': ['TonyRL'], }; diff --git a/lib/v2/sysu/radar.js b/lib/v2/sysu/radar.js index 34b011a461..d8ef1ae69c 100644 --- a/lib/v2/sysu/radar.js +++ b/lib/v2/sysu/radar.js @@ -9,5 +9,13 @@ module.exports = { target: '/sysu/cse', }, ], + ygafz: [ + { + title: '粤港澳发展研究院', + docs: 'https://docs.rsshub.app/universities.html#zhong-shan-da-xue', + source: ['/:type?'], + target: '/sysu/ygafz/:type?', + }, + ], }, }; diff --git a/lib/v2/sysu/router.js b/lib/v2/sysu/router.js index 31d36c7e2d..05e9753ced 100644 --- a/lib/v2/sysu/router.js +++ b/lib/v2/sysu/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { router.get('/cse', require('./cse')); + router.get('/ygafz/:type?', require('./ygafz')); }; diff --git a/lib/v2/sysu/ygafz.js b/lib/v2/sysu/ygafz.js new file mode 100644 index 0000000000..150f4d4bb4 --- /dev/null +++ b/lib/v2/sysu/ygafz.js @@ -0,0 +1,69 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const logger = require('@/utils/logger'); +const { CookieJar } = require('tough-cookie'); + +module.exports = async (ctx) => { + const { type = 'notice' } = ctx.params; + const baseUrl = 'https://ygafz.sysu.edu.cn'; + const url = `${baseUrl}/${type}`; + + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.setRequestInterception(true); + page.on('request', (request) => { + request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort(); + }); + + logger.debug(`Requesting ${url}`); + await page.goto(url, { + waitUntil: 'domcontentloaded', + }); + await page.waitForSelector('[data-block-plugin-id]'); + const response = await page.content(); + + const cookieJar = new CookieJar(); + const cookies = await page.cookies(); + cookies.reduce((jar, cookie) => { + jar.setCookie(`${cookie.name}=${cookie.value}`, url); + return jar; + }, cookieJar); + + browser.close(); + + const $ = cheerio.load(response); + const list = $('.list-content a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('p').text(), + link: `${baseUrl}${item.attr('href')}`, + pubDate: parseDate(item.find('.date').text()), // 2023-03-22 + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data } = await got(item.link, { + cookieJar, + }); + const $ = cheerio.load(data); + + item.author = $('.article-submit') + .text() + .match(/发布人:(.*)/)[1]; + item.description = $('div[data-block-plugin-id="entity_field:node:body"]').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: url, + item: items, + }; +};