mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 01:58:11 +08:00
57
lib/v2/nowcoder/discuss.js
Normal file
57
lib/v2/nowcoder/discuss.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const host = 'https://www.nowcoder.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
const order = ctx.params.order;
|
||||
|
||||
const link = `https://www.nowcoder.com/discuss?type=${type}&order=${order}`;
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const type_name = $('a.discuss-tab.selected').text();
|
||||
const order_name = $('li.selected a').text();
|
||||
|
||||
const list = $('li.clearfix')
|
||||
.map(function () {
|
||||
const info = {
|
||||
title: $(this).find('div.discuss-main.clearfix a:first').text().trim().replace('\n', ' '),
|
||||
link: $(this).find('div.discuss-main.clearfix a[rel]').attr('href'),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((info) => {
|
||||
const title = info.title || 'tzgg';
|
||||
const itemUrl = new URL(info.link, host).href.replace(new RegExp('^(.*)[?](.*)$'), '$1');
|
||||
|
||||
return ctx.cache.tryGet(itemUrl, async () => {
|
||||
const response = await got.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const date_value = $('span.post-time').text();
|
||||
|
||||
const description = $('.nc-post-content').html();
|
||||
|
||||
return {
|
||||
title,
|
||||
link: itemUrl,
|
||||
description,
|
||||
pubDate: timezone(parseDate(date_value), +8),
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${type_name}${order_name}——牛客网讨论区`,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
48
lib/v2/nowcoder/experience.js
Normal file
48
lib/v2/nowcoder/experience.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const host = 'https://www.nowcoder.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const params = new URLSearchParams(ctx.query);
|
||||
params.append('tagId', ctx.params.tagId);
|
||||
|
||||
const link = new URL('/discuss/experience/json', host);
|
||||
|
||||
// const link = `https://www.nowcoder.com/discuss/experience/json?tagId=${tagId}&order=${order}&companyId=${companyId}&phaseId=${phaseId}`;
|
||||
link.search = params;
|
||||
const response = await got.get(link.toString());
|
||||
const data = response.data.data;
|
||||
|
||||
const list = data.discussPosts.map((x) => {
|
||||
const info = {
|
||||
title: x.postTitle,
|
||||
link: new URL('discuss/' + x.postId, host).href,
|
||||
author: x.author,
|
||||
pubDate: timezone(parseDate(x.createTime), +8),
|
||||
category: x.postTypeName,
|
||||
};
|
||||
return info;
|
||||
});
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((info) =>
|
||||
ctx.cache.tryGet(info.link, async () => {
|
||||
const response = await got.get(info.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
info.description = $('.nc-post-content').html();
|
||||
|
||||
return info;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `牛客面经Tag${ctx.params.tagId}`,
|
||||
link: link.href,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
57
lib/v2/nowcoder/jobcenter.js
Normal file
57
lib/v2/nowcoder/jobcenter.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = `https://www.nowcoder.com/job/center/`;
|
||||
const currentUrl = `${rootUrl}?${ctx.params.type ? 'type=' + ctx.params.type : ''}${ctx.params.city ? '&city=' + ctx.params.city : ''}${ctx.params.order ? '&order=' + ctx.params.order : ''}${
|
||||
ctx.params.recruitType ? '&recruitType=' + ctx.params.recruitType : ''
|
||||
}${ctx.params.latest ? '&latest=' + ctx.params.latest : ''}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('ul.reco-job-list li')
|
||||
.slice(0, 30)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const title = item.find('a.reco-job-title');
|
||||
const company = item.find('div.reco-job-com a');
|
||||
const time = item.find('div.reco-job-detail span').eq(1).text();
|
||||
const date = new Date();
|
||||
if (time.indexOf('天') !== -1) {
|
||||
const day = time.split('天')[0];
|
||||
date.setDate(date.getDate() - day);
|
||||
} else if (time.indexOf('小时') !== -1) {
|
||||
const hour = time.split('小时')[0];
|
||||
date.setHours(date.getHours() - hour);
|
||||
}
|
||||
return {
|
||||
title: `${company.text()} | ${title.text()}`,
|
||||
link: url.resolve(rootUrl, title.attr('href')),
|
||||
pubDate: date.toUTCString(),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
item.description = content('div.rec-job').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${ctx.params.recruitType ? (ctx.params.recruitType === '2' ? '社招广场' : '实习广场') : '实习广场'} - 牛客网`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
7
lib/v2/nowcoder/maintainer.js
Normal file
7
lib/v2/nowcoder/maintainer.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
'/discuss/:type/:order': ['LogicJake'],
|
||||
'/experience/:tagId': ['huyyi'],
|
||||
'/jobcenter/:recruitType?/:city?/:type?/:order?/:latest?': ['nczitzk'],
|
||||
'/recommend': ['junfengP'],
|
||||
'/schedule/:propertyId?/:typeId?': ['junfengP'],
|
||||
};
|
||||
40
lib/v2/nowcoder/radar.js
Normal file
40
lib/v2/nowcoder/radar.js
Normal file
@@ -0,0 +1,40 @@
|
||||
module.exports = {
|
||||
'nowcoder.com': {
|
||||
_name: '牛客网',
|
||||
'.': [
|
||||
{
|
||||
title: '面经',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#niu-ke-wang-mian-jing',
|
||||
source: ['/'],
|
||||
target: '/nowcoder/experience',
|
||||
},
|
||||
{
|
||||
title: '讨论区',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#niu-ke-wang',
|
||||
source: ['/discuss'],
|
||||
target: (_params, url) => {
|
||||
const href = new URL(url);
|
||||
return `/nowcoder/${href.searchParams.get('type')}/${href.searchParams.get('order')}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '实习广场 & 社招广场',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#niu-ke-wang',
|
||||
source: ['/'],
|
||||
target: '/nowcoder/jobcenter',
|
||||
},
|
||||
{
|
||||
title: '校招日程',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#niu-ke-wang',
|
||||
source: ['/'],
|
||||
target: '/nowcoder/schedule',
|
||||
},
|
||||
{
|
||||
title: '求职推荐',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#niu-ke-wang',
|
||||
source: ['/'],
|
||||
target: '/nowcoder/recommend',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
20
lib/v2/nowcoder/recommend.js
Normal file
20
lib/v2/nowcoder/recommend.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = `https://www.nowcoder.com/recommand/activity?token=&type=3&_=${new Date().getTime()}`;
|
||||
const responseBody = (await got.get(link)).data;
|
||||
if (responseBody.code !== 0) {
|
||||
throw Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
|
||||
}
|
||||
const data = responseBody.data.activitys;
|
||||
ctx.state.data = {
|
||||
title: '牛客网-推荐',
|
||||
link: 'https://www.nowcoder.com/recommend',
|
||||
description: '牛客网-推荐',
|
||||
item: data.map((item) => ({
|
||||
title: item.name,
|
||||
description: `<img src="${item.img}">`,
|
||||
link: `https://www.nowcoder.com${item.url}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
7
lib/v2/nowcoder/router.js
Normal file
7
lib/v2/nowcoder/router.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/discuss/:type/:order', require('./discuss'));
|
||||
router.get('/experience/:tagId', require('./experience'));
|
||||
router.get('/jobcenter/:recruitType?/:city?/:type?/:order?/:latest?', require('./jobcenter'));
|
||||
router.get('/recommend', require('./recommend'));
|
||||
router.get('/schedule/:propertyId?/:typeId?', require('./schedule'));
|
||||
};
|
||||
32
lib/v2/nowcoder/schedule.js
Normal file
32
lib/v2/nowcoder/schedule.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const propertyId = ctx.params.propertyId ? ctx.params.propertyId : 0;
|
||||
const typeId = ctx.params.typeId ? ctx.params.typeId : 0;
|
||||
|
||||
const link = `https://www.nowcoder.com/school/schedule/data?token=&query=&typeId=${typeId}&propertyId=${propertyId}&onlyFollow=false&_=${new Date().getTime()}`;
|
||||
const responseBody = (await got(link)).data;
|
||||
if (responseBody.code !== 0) {
|
||||
throw Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
|
||||
}
|
||||
const data = responseBody.data.companyList;
|
||||
|
||||
ctx.state.data = {
|
||||
title: '名企校招日程',
|
||||
link: 'https://www.nowcoder.com/school/schedule',
|
||||
description: '名企校招日程',
|
||||
item: data.map((item) => {
|
||||
let desc = `<tr><td><img src="${item.logo}" referrerpolicy="no-referrer""></td></tr>`;
|
||||
item.schedules.forEach((each) => {
|
||||
desc += `<tr><td>${each.content}</td><td>${each.time}</td></tr>`;
|
||||
});
|
||||
return {
|
||||
title: item.name,
|
||||
description: `<table>${desc}</table>`,
|
||||
pubDate: parseDate(item.createTime),
|
||||
link: `https://www.nowcoder.com/school/schedule/${item.id}`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user