Skip to content

Commit

Permalink
Merge pull request DIYgod#6589 from laampui/ahut
Browse files Browse the repository at this point in the history
fix: 安徽工业大学
  • Loading branch information
NeverBehave authored Jan 11, 2021
2 parents 2c0d14e + 4730802 commit b9b00a1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 127 deletions.
67 changes: 24 additions & 43 deletions lib/routes/universities/ahut/cstzgg.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,39 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');

module.exports = async (ctx) => {
const url = `http://jsjxy.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1887`;
const response = await got({
method: 'get',
url: url,
});
const response = await got.get('http://jsjxy.ahut.edu.cn/index/tzgg.htm');
const $ = cheerio.load(response.data);
$('.clickstyle1022').remove();
$('td[width = "1%"]').remove();
$('tr[height = "1"]').remove();
$('td[colspan="3"]').remove();
$('.leaderfont47822').remove();
// ## 获取列表
const list = $('.winstyle47822 > tbody > tr').get();
// ## 定义输出的item

// 获取列表
const list = $('a.c259382')
.map((index, ele) => ({
title: $(ele).attr('title'),
link: url.resolve('http://jsjxy.ahut.edu.cn/', $(ele).attr('href')),
}))
.get();

// 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
// 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text().replace(/^[\s]+|[\s]+$/g, '');
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
if (singleUrl.search('http') === -1) {
singleUrl = 'http://jsjxy.ahut.edu.cn' + singleUrl;
}
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息
// 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const detail_response = await got.get(item.link);
const $ = cheerio.load(detail_response.data);
const detail_content = $('.contentstyle47853 > div').html();
// ### 设置 RSS feed item
const single = {
title: title.replace(/(^\s*)|(\s*$)/g, ''),
link: singleUrl,
// author: author,
description: detail_content,
// pubDate: updateDate,
};
// // ### 设置缓存
ctx.cache.set(singleUrl, JSON.stringify(single));
return Promise.resolve(single);
// }

// 设置 RSS feed item
item.description = $('.contentstyle47853 > div').html();
item.pubDate = new Date($('.timestyle47853').text().trim());

// 设置缓存
ctx.cache.set(item.link, JSON.stringify(item));
return Promise.resolve(item);
})
);
ctx.state.data = {
Expand Down
63 changes: 22 additions & 41 deletions lib/routes/universities/ahut/jwc.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,37 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');

module.exports = async (ctx) => {
const url = `http://jwc.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1082`;
const response = await got({
method: 'get',
url: url,
});
const response = await got.get('http://jwc.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1082');
const $ = cheerio.load(response.data);
$('tr[height="1"]').remove();
$('td[width="1%"]').remove();
$('td[colspan="3"]').remove();
// ## 获取列表
const list = $('.winstyle44456 > tbody > tr >td').get();
// ## 定义输出的item

// 获取列表
const list = $('.winstyle44566 tr')
.map((index, ele) => ({
title: $('a', ele).attr('title'),
link: url.resolve('http://jwc.ahut.edu.cn/', $('a', ele).attr('href')),
}))
.get();

// 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
// 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text();
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
if (singleUrl.search('http') === -1) {
singleUrl = 'http://jwc.ahut.edu.cn' + singleUrl;
}
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息
// 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const detail_response = await got.get(item.link);
const $ = cheerio.load(detail_response.data);
const detail_content = $('.winstyle44457 > tbody').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);
// }
// 设置 RSS feed item
item.description = $('.winstyle44457 > tbody').html();
item.pubDate = new Date($('.timestyle44457').text().trim());
// 设置缓存
ctx.cache.set(item.link, JSON.stringify(item));
return Promise.resolve(item);
})
);
ctx.state.data = {
Expand Down
66 changes: 23 additions & 43 deletions lib/routes/universities/ahut/news.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,38 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');

module.exports = async (ctx) => {
const url = `http://news.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1002`;
const response = await got({
method: 'get',
url: url,
});
const response = await got.get('http://news.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1002');
const $ = cheerio.load(response.data);
$('tr[height="26"]').slice(20);
$('td[width="1%"]').remove();
$('.clickstyle1022').remove();
$('td[colspan="3"]').remove();
$('.leaderfont1022').remove();
// ## 获取列表
const list = $('.winstyle1022 > tbody > tr > td').get();
// ## 定义输出的item

// 获取列表
const list = $('.winstyle247968 a.c247968')
.map((index, ele) => ({
title: $(ele).attr('title'),
link: url.resolve('http://news.ahut.edu.cn/', $(ele).attr('href')),
}))
.get();
// 定义输出的item
const out = await Promise.all(
// ### 遍历列表,筛选出自己想要的内容
// 遍历列表,筛选出自己想要的内容
list.map(async (item) => {
const itemSingle = cheerio.load(item);
const title = itemSingle.text().trim();
const re = /<a[^>]*href=['"]([^"]*)['"][^>]*>/g;
let singleUrl = '';
if (re.exec(itemSingle.html()) !== null) {
singleUrl = RegExp.$1;
}
if (singleUrl.search('http') === -1) {
singleUrl = 'http://news.ahut.edu.cn' + singleUrl;
}
const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息
// ### 判断缓存是否存在,如果存在即跳过此次获取的信息
const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息
// 判断缓存是否存在,如果存在即跳过此次获取的信息
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
// 获取详情页面的介绍
const detail_response = await got({
method: 'get',
url: singleUrl,
});
const detail_response = await got.get(item.link);
const $ = cheerio.load(detail_response.data);
const detail_content = $('.winstyle1023').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);
// }

// 设置 RSS feed item
item.description = $('.winstyle1023').html();
item.pubDate = new Date($('.timestyle1023').text().trim());

// 设置缓存
ctx.cache.set(item.link, JSON.stringify(item));
return Promise.resolve(item);
})
);
ctx.state.data = {
Expand Down

0 comments on commit b9b00a1

Please sign in to comment.