diff --git a/lib/routes/eastday/sh.js b/lib/routes/eastday/sh.js index c7ab57b7d..4d38551a3 100644 --- a/lib/routes/eastday/sh.js +++ b/lib/routes/eastday/sh.js @@ -6,41 +6,47 @@ module.exports = async (ctx) => { const domain = 'http://wap.eastday.com'; const response = await got({ - method: 'get', - url: `${domain}/node2/node3/n5/index5_t81.html`, + method: 'post', + url: `https://apin.eastday.com/api/news/list`, + json: true, + data: { + channelId: '15', + currentPage: 1, + pageSize: 20, + appId: '190504', + deviceId: '00000000', + version: '0.0.0.2', + }, }); const data = JSON.parse(response.body.trim()); const result = await Promise.all( - data.newslist.map(async (item) => { - const link = item.newsurl.match(/^http/) ? item.newsurl : domain + item.newsurl; - const description = item.imgurl1 ? `
` : ''; + data.list.map(async (item) => { + const link = item.url; const entity = { - title: item.newstitle, - author: item.source, - description, - pubDate: new Date(item.createTime).toUTCString(), + title: item.title, + description: item.abstracts + '...', + pubDate: new Date(item.time).toUTCString(), link, }; try { - const cacheKey = `eastday_sh_${item.newsurl}`; - const xmlLink = domain + item.newsurl.split('_')[0] + '_K77.xml'; + const cacheKey = `eastday_sh_${link}`; // 判断缓存中是否存在 const cacheValue = await ctx.cache.get(cacheKey); if (cacheValue) { - entity.description += cacheValue; + entity.description = cacheValue; } else { const article = await got({ method: 'get', - url: xmlLink, + url: link, }); // 解析html内容 - const $ = cheerio.load(article.body, { xmlMode: true }); - const content = $('zw').text(); + const $ = cheerio.load(article.body); + const content = $('.article_wrapper .mainLayer .content').html(); // 存放到缓存区 ctx.cache.set(cacheKey, content); - entity.description += content; + entity.description = content; } } catch (error) { logger.error(error);