diff --git a/lib/routes/netease/open/vip.js b/lib/routes/netease/open/vip.js index 1d6c1e84a8..7f6122d66d 100644 --- a/lib/routes/netease/open/vip.js +++ b/lib/routes/netease/open/vip.js @@ -2,60 +2,38 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { - const url = 'https://open.163.com/'; + const url = 'https://vip.open.163.com'; const list_response = await got.get(url); const $ = cheerio.load(list_response.data); - const list = $('.tabcon > div:nth-child(1) ul.list li').toArray(); - - const parseContent = (htmlString) => { - const $ = cheerio.load(htmlString); - - const author = $('.CourseCommonDetail_info > div:nth-child(4)'); - const content = $('.CourseCommonDetail_contentDesc'); - - return { - author: author.text().trim(), - description: content.html(), - pubDate: new Date(), - }; - }; - - const out = await Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const title = $('.ltxt').text().trim(); - const link = $('a.item').attr('href').split('?')[0]; - - const cache = await ctx.cache.get(link); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } - - const rssitem = { - title: title, - link: link, + const list = $('.CourseListItem_ListItem') + .map((index, ele) => { + $('.CourseListItem_oriPrice', ele).remove(); + const price = $('.CourseListItem_price', ele).text().trim(); + return { + title: price + ' - ' + $('.CourseListItem_title', ele).text(), + link: url + $(ele).attr('href'), }; - - try { - const response = await got.get(link); - const result = parseContent(response.data); - - rssitem.author = result.author; - rssitem.description = result.description; - rssitem.pubDate = result.pubDate; - } catch (err) { - return Promise.resolve(''); - } - ctx.cache.set(link, JSON.stringify(rssitem)); - return Promise.resolve(rssitem); }) + .get(); + + const item = await Promise.all( + list.slice(0, 10).map((item) => + ctx.cache.tryGet(item.link, async () => { + const res = await got.get(item.link); + const s = cheerio.load(res.data); + s('img').css('max-width', '100%'); + const toc = s('.CourseCommonDetail_contentItem').eq(1).html(); + item.description = `