forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 南京理工大学电光学院; fix: 南京理工大学研究生院 (DIYgod#4298)
- Loading branch information
Showing
5 changed files
with
120 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const date = require('@/utils/date'); | ||
const cheerio = require('cheerio'); | ||
const { getContent } = require('@/routes/universities/njust/eo/util'); | ||
|
||
const map = new Map([ | ||
['16tz', { title: '南京理工大学电光16 -- 通知公告', id: '/_t217/tzgg/list.htm' }], | ||
['16dt', { title: '南京理工大学电光16 -- 主任寄语', id: '/_t217/zrjy/list.htm' }], | ||
['17tz', { title: '南京理工大学电光17 -- 年级通知', id: '/_t689/njtz/list.htm' }], | ||
['17dt', { title: '南京理工大学电光17 -- 每日动态', id: '/_t689/mrdt/list.htm' }], | ||
['18tz', { title: '南京理工大学电光18 -- 年级通知', id: '/_t900/njtz_10234/list.htm' }], | ||
['18dt', { title: '南京理工大学电光18 -- 主任寄语', id: '/_t900/zrjy_10251/list.htm' }], | ||
['19tz', { title: '南京理工大学电光19 -- 通知公告', id: '/_t1163/tzgg_11606/list.htm' }], | ||
['19dt', { title: '南京理工大学电光19 -- 每日动态', id: '/_t1163/mrdt_11608/list.htm' }], | ||
]); | ||
|
||
const baseUrl = 'http://dgxg.njust.edu.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const grade = ctx.params.grade || '17'; | ||
const type = ctx.params.type || 'tz'; | ||
const category = grade + type; | ||
const id = map.get(category).id; | ||
|
||
const html = await getContent(baseUrl + id); | ||
const $ = cheerio.load(html); | ||
const list = $('li.list_item'); | ||
|
||
ctx.state.data = { | ||
title: map.get(category).title, | ||
link: baseUrl + '/' + id.split('/')[1] + '/main.htm', | ||
item: | ||
list && | ||
list | ||
.map((index, item) => ({ | ||
title: $(item) | ||
.find('a') | ||
.text() | ||
.trim(), | ||
pubDate: date( | ||
$(item) | ||
.find('span.Article_PublishDate') | ||
.text() | ||
), | ||
link: $(item) | ||
.find('a') | ||
.attr('href'), | ||
})) | ||
.get(), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const delay = (timeout = 1000) => new Promise((resolve) => setTimeout(resolve, timeout)); | ||
|
||
async function getContent(url) { | ||
const browser = await require('@/utils/puppeteer')(); | ||
try { | ||
const page = await browser.newPage(); | ||
page.waitForNavigation({ | ||
timeout: 20000, | ||
}); | ||
// 更改 window.navigator.webdriver 值以避开反爬 | ||
await page.evaluateOnNewDocument(() => { | ||
// eslint-disable-next-line no-undef | ||
Object.defineProperty(navigator, 'webdriver', { | ||
get: () => undefined, | ||
}); | ||
}); | ||
await page.goto(url); | ||
await delay(1000); | ||
const content = await page.content(); | ||
return content; | ||
} finally { | ||
browser.close(); | ||
} | ||
} | ||
|
||
module.exports = { | ||
getContent, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
const got = require('@/utils/got'); | ||
const date = require('@/utils/date'); | ||
const cheerio = require('cheerio'); | ||
const { getContent } = require('@/routes/universities/njust/eo/util'); | ||
|
||
const map = new Map([ | ||
[1, { title: '南京理工大学研究生院 -- 通知公告', id: '/sytzgg_4568' }], | ||
[2, { title: '南京理工大学研究生院 -- 学术公告', id: '/xshdggl' }], | ||
]); | ||
|
||
const baseUrl = 'http://gs.njust.edu.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const type = Number.parseInt(ctx.params.type); | ||
const id = map.get(type).id; | ||
const baseUrl = 'http://gs.njust.edu.cn'; | ||
const res = await got({ | ||
method: 'get', | ||
url: baseUrl + id + '/list.htm', | ||
headers: { | ||
Referer: 'https://gs.njust.edu.cn/', | ||
}, | ||
}); | ||
const $ = cheerio.load(res.data); | ||
const list = $('.wp_article_list li').slice(0, 10); | ||
|
||
const html = await getContent(baseUrl + id + '/list.htm'); | ||
const $ = cheerio.load(html); | ||
const list = $('li.list_item'); | ||
|
||
ctx.state.data = { | ||
title: map.get(type).title, | ||
link: 'https://gs.njust.edu.cn', | ||
link: 'http://gs.njust.edu.cn', | ||
item: | ||
list && | ||
list | ||
.map((index, item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.find('a').text(), | ||
link: `${baseUrl + $(item.find('a')).attr('href')}`, | ||
pubDate: new Date(item.find('.Article_PublishDate').text()).toUTCString(), | ||
}; | ||
}) | ||
.map((index, item) => ({ | ||
title: $(item) | ||
.find('a') | ||
.text() | ||
.trim(), | ||
pubDate: date( | ||
$(item) | ||
.find('span.Article_PublishDate') | ||
.text() | ||
), | ||
link: $(item) | ||
.find('a') | ||
.attr('href'), | ||
})) | ||
.get(), | ||
}; | ||
}; |