forked from DIYgod/RSSHub
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 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,63 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
const baseUrl = 'http://neunews.neu.edu.cn'; | ||
module.exports = async (ctx) => { | ||
const type = ctx.params.type; | ||
const newsUrl = `${baseUrl}/${type}/list.htm`; | ||
const response = await got({ | ||
method: 'get', | ||
url: newsUrl, | ||
}); | ||
|
||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
|
||
const title = $('title').text(); | ||
const items = $('.column-news-list > .news_list > .news > .news_title') | ||
.slice(0, 10) | ||
.children(); | ||
const results = []; | ||
items.each(async (index, item) => { | ||
const label = $(item); | ||
const title = $(label).attr('title'); | ||
const url = baseUrl + $(label).attr('href'); | ||
const description = await ctx.cache.tryGet(url, async () => { | ||
const result = await got.get(url); | ||
const $ = cheerio.load(result.data); | ||
// 处理部分格式 | ||
$('article') | ||
.find('span') | ||
.each(function() { | ||
const temp = $(this).text(); | ||
$(this).replaceWith(temp); | ||
}); | ||
$('article') | ||
.find('div') | ||
.each(function() { | ||
const temp = $(this).html(); | ||
$(this).replaceWith(temp); | ||
}); | ||
$('article') | ||
.find('a') | ||
.remove(); | ||
$('article') | ||
.find('p') | ||
.each(function() { | ||
$(this).removeAttr('style'); | ||
$(this).removeAttr('class'); | ||
}); | ||
return $('article').html(); | ||
}); | ||
const result = { | ||
title: title, | ||
description: description, | ||
link: url, | ||
}; | ||
results.push(result); | ||
}); | ||
ctx.state.data = { | ||
title: title, | ||
item: results, | ||
}; | ||
}; |