feat:增加智联招聘 北华航天工业学院 (#2928)

This commit is contained in:
SunShinenny
2019-08-26 11:02:03 +08:00
committed by DIYgod
parent 4e3d3685db
commit ab039b75a6
9 changed files with 301 additions and 17 deletions

View File

@@ -1257,6 +1257,12 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="sanmmm" example="/getitfree/search/windows" path="/getitfree/search/:keyword" :paramsDesc="['搜索关键词']"/> <Route author="sanmmm" example="/getitfree/search/windows" path="/getitfree/search/:keyword" :paramsDesc="['搜索关键词']"/>
## 智联招聘
### 搜索
<Route author="SunShinenny" example="/zhilian/台州/JavaScript" path="/zhilian/:city/:keyword" :paramsDesc="['城市「如若无该城市数据,将会报错」','搜索关键词']"/>
## 中国大学 MOOC(慕课) ## 中国大学 MOOC(慕课)
### 最新 ### 最新

View File

@@ -24,6 +24,20 @@ pageClass: routes
<Route author="exuanbo" example="/polimi/news" path="/polimi/news/:language?" :paramsDesc="['English language code en']" /> <Route author="exuanbo" example="/polimi/news" path="/polimi/news/:language?" :paramsDesc="['English language code en']" />
## 北华航天工业学院
### 新闻
<Route author="SunShinenny" example="/nciae/news" path="/universities/nciae/news" />
### 学术信息
<Route author="SunShinenny" example="/nciae/xsxx" path="/universities/nciae/xsxx" />
### 通知公告
<Route author="SunShinenny" example="/nciae/tzgg" path="/universities/nciae/tzgg" />
## 北京大学 ## 北京大学
### 信科公告通知 ### 信科公告通知

View File

@@ -1653,6 +1653,18 @@ router.get('/cneb/guoneinews', require('./routes/cneb/guoneinews'));
// 邮箱 // 邮箱
router.get('/mail/imap/:email', require('./routes/mail/imap')); router.get('/mail/imap/:email', require('./routes/mail/imap'));
// 智联招聘
router.get('/zhilian/:city/:keyword', require('./routes/zhilian/index'));
// 北华航天工业学院 - 新闻
router.get('/nciae/news', require('./routes/universities/nciae/news'));
// 北华航天工业学院 - 通知公告
router.get('/nciae/tzgg', require('./routes/universities/nciae/tzgg'));
// 北华航天工业学院 - 学术信息
router.get('/nciae/xsxx', require('./routes/universities/nciae/xsxx'));
// cfan // cfan
router.get('/cfan/news', require('./routes/cfan/news')); router.get('/cfan/news', require('./routes/cfan/news'));

View File

@@ -43,21 +43,16 @@ module.exports = async (ctx) => {
url: page, url: page,
}); });
const data = response.data; const data = response.data;
const fs = require('fs');
fs.writeFile('result.txt', data, function(err) {
if (err) {
return console.error(err);
}
});
const $ = cheerio.load(data); const $ = cheerio.load(data);
const list = $('#whTopSlide > div.bd > ul > li > a').get(); const list = $('#whTopSlide > div.bd > ul > li > a').get();
console.log(list.length);
const process = await Promise.all( const process = await Promise.all(
list.map(async (item) => { list.map(async (item) => {
let itemUrl = $(item).attr('href'); let itemUrl = $(item).attr('href');
if (itemUrl.indexOf('./') === 0) { if (itemUrl.indexOf('./') === 0) {
itemUrl = host + itemUrl.substring(2); itemUrl = host + itemUrl.substring(1);
} else if (itemUrl.indexOf('/') === 0) {
itemUrl = host + itemUrl;
} }
const single = { const single = {
title: $(item).attr('title'), title: $(item).attr('title'),

View File

@@ -1,40 +1,43 @@
const got = require('@/utils/got'); const got = require('@/utils/got');
module.exports = async (ctx) => { module.exports = async (ctx) => {
// const id = ctx.params.id;
const api_url = `https://baobab.kaiyanapp.com/api/v5/index/tab/allRec`; const api_url = `https://baobab.kaiyanapp.com/api/v5/index/tab/allRec`;
const response = await got({ const response = await got({
method: 'get', method: 'get',
url: api_url, url: api_url,
}); });
// ## 获取列表
const list = response.data.itemList[0].data.itemList; const list = response.data.itemList[0].data.itemList;
// ## 定义输出的item
const out = await Promise.all( const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
list.map(async (item) => { list.map(async (item) => {
if (item.type === 'followCard') { if (item.type === 'followCard') {
// 截取Json一部分 // #### 截取Json中需要的部分,便于下方变量快速取值
const content = item.data.content; const content = item.data.content;
// 得到需要的RSS信息 // #### 得到需要的RSS信息
const title = content.data.title; // 标题 const title = content.data.title; // 标题
const date = item.data.header.time; // 发布日期 const date = item.data.header.time; // 发布日期
const videoUrl = content.data.playUrl; // 原装视频链接
const itemUrl = `<video src="${content.data.playUrl}" controls="controls"></video>`; // 视频链接 const itemUrl = `<video src="${content.data.playUrl}" controls="controls"></video>`; // 视频链接
const imgUrl = `<img src="${content.data.cover.feed}" />`; // 图片链接 const imgUrl = `<img src="${content.data.cover.feed}" />`; // 图片链接
const author = content.data.author.name; // 作者 const author = content.data.author.name; // 作者
const description = content.data.description + '<br/>' + imgUrl + '<br/>' + itemUrl; // 拼接出描述 const description = content.data.description + '<br/>' + imgUrl + '<br/>' + itemUrl; // 拼接出详情,包括文字描述、封面图、视频链接
const cache = await ctx.cache.get(itemUrl); // 得到全局中的缓存信息 const cache = await ctx.cache.get(itemUrl); // ### 得到全局中的缓存信息
// 判断缓存是否存在,如果存在即跳过此次获取的信息 // ### 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) { if (cache) {
return Promise.resolve(JSON.parse(cache)); return Promise.resolve(JSON.parse(cache));
} }
// 设置 RSS feed item // ### 设置 RSS feed item
const single = { const single = {
title: title, title: title,
link: itemUrl, link: videoUrl,
author: author, author: author,
description: description, description: description,
pubDate: new Date(date).toUTCString(), pubDate: new Date(date).toUTCString(),
}; };
// 设置缓存 // ### 设置缓存
ctx.cache.set(itemUrl, JSON.stringify(single)); ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single); return Promise.resolve(single);
} }

View File

@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = `http://nciae.edu.cn/index/xw2.htm`;
const response = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(response.data);
// ## 获取列表
const list = $('#container > ul > li > a').get();
// ## 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text();
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
singleUrl = singleUrl.replace('..', 'http://nciae.edu.cn');
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const $ = cheerio.load(detail_response.data);
const detail_content = $('#content > form').html();
// ### 设置 RSS feed item
const single = {
title: title,
link: singleUrl,
// author: author,
description: detail_content,
// pubDate: updateDate,
};
// // ### 设置缓存
ctx.cache.set(singleUrl, JSON.stringify(single));
return Promise.resolve(single);
// }
})
);
ctx.state.data = {
title: `新闻 - 北华航天工业学院`,
link: 'http://nciae.edu.cn/index/xw2.htm',
description: `新闻 - 北华航天工业学院`,
item: out,
};
};

View File

@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = `http://nciae.edu.cn/index/tzgg.htm`;
const response = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(response.data);
// ## 获取列表
const list = $('#container > ul > li > a').get();
// ## 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text();
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
singleUrl = singleUrl.replace('..', 'http://nciae.edu.cn');
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const $ = cheerio.load(detail_response.data);
const detail_content = $('#content > form').html();
// ### 设置 RSS feed item
const single = {
title: title,
link: singleUrl,
// author: author,
description: detail_content,
// pubDate: updateDate,
};
// // ### 设置缓存
ctx.cache.set(singleUrl, JSON.stringify(single));
return Promise.resolve(single);
// }
})
);
ctx.state.data = {
title: `通知公告 - 北华航天工业学院`,
link: 'http://nciae.edu.cn/index/xw2.htm',
description: `通知公告 - 北华航天工业学院`,
item: out,
};
};

View File

@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = `http://nciae.edu.cn/index/xsxx.htm`;
const response = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(response.data);
// ## 获取列表
const list = $('#container > ul > li > a').get();
// ## 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text();
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>(.*?)<\/a>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
singleUrl = singleUrl.replace('..', 'http://nciae.edu.cn');
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const $ = cheerio.load(detail_response.data);
const detail_content = $('#content > form').html();
// ### 设置 RSS feed item
const single = {
title: title,
link: singleUrl,
// author: author,
description: detail_content,
// pubDate: updateDate,
};
// // ### 设置缓存
ctx.cache.set(singleUrl, JSON.stringify(single));
return Promise.resolve(single);
// }
})
);
ctx.state.data = {
title: `学术信息 - 北华航天工业学院`,
link: 'http://nciae.edu.cn/index/xw2.htm',
description: `学术信息 - 北华航天工业学院`,
item: out,
};
};

View File

@@ -0,0 +1,80 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const city = ctx.params.city;
const keyword = ctx.params.keyword;
const city_api_url = `https://fe-api.zhaopin.com/c/i/city-page/user-city?ipCity=${encodeURI(city)}`;
const city_response = await got({
method: 'get',
url: city_api_url,
});
const city_response_data = city_response.data.data;
if (city_response_data.name === undefined) {
console.log('No This City');
} else {
const job_api_url = `https://fe-api.zhaopin.com/c/i/sou?pageSize=20&cityId=${city_response_data.code}&workExperience=-1&education=5&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=${encodeURI(keyword)}&kt=3`;
const job_response = await got({
method: 'get',
url: job_api_url,
});
// ## 获取列表
const list = job_response.data.data.results;
// ## 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const jobName = item.jobName;
const companyName = item.company.name;
const companyType = item.company.type.name;
const companySize = item.company.size.name;
const companyUrl = item.company.url;
const companyLogo = item.companyLogo; // logo
const salary = item.salary;
const jobType = item.jobType.items[0].name;
const positionURL = item.positionURL; // 原网页链接
const updateDate = item.updateDate; // 更新时间
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: positionURL,
});
const $ = cheerio.load(detail_response.data);
const detail_content = $('.describtion').html();
// # 拼接相关信息
// ## 拼接标题
const title = `${jobName}[${salary}]-${jobType}`;
// ## 公司信息
const companyDes = `<h3>${companyName}</h3><h4>${companyType}[${companySize}]</h4><a href='${companyUrl}'>点击查看公司详情</a><br/><img url='${companyLogo}'</img>`;
const cache_information = positionURL + updateDate; // 确保唯一性
const cache = await ctx.cache.get(cache_information); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// ### 设置 RSS feed item
const single = {
title: title,
link: positionURL,
// author: author,
description: `<a href='${positionURL}'>如需申请此工作,建议打开原网页进行操作。</a><br/><hr/>${companyDes}<br/><hr/>${detail_content !== null ? detail_content : ''}`,
pubDate: updateDate,
};
// // ### 设置缓存
ctx.cache.set(cache_information, JSON.stringify(single));
return Promise.resolve(single);
// }
})
);
ctx.state.data = {
title: `${city}-${keyword} 相关工作 - 智联招聘`,
link: '',
description: `${city}${keyword} 相关工作 - 智联招聘`,
item: out,
};
}
};