feat: 增加虎嗅首页资讯,修复虎嗅网页元素更新导致的问题 (#3316)

This commit is contained in:
Henry Wang
2019-10-25 17:26:26 +08:00
committed by DIYgod
parent 849058b119
commit 5cf7f45077
5 changed files with 44 additions and 3 deletions
+4
View File
@@ -355,6 +355,10 @@ pageClass: routes
## 虎嗅
### 首页资讯
<Route author="HenryQW" example="/huxiu/article" path="/huxiu/article" />
### 标签
<Route author="xyqfer HenryQW" example="/huxiu/tag/291" path="/huxiu/tag/:id" :paramsDesc="['标签 id']" />
+1
View File
@@ -995,6 +995,7 @@ router.get('/zimuzu/resource/:id?', require('./routes/zimuzu/resource'));
router.get('/huxiu/tag/:id', require('./routes/huxiu/tag'));
router.get('/huxiu/search/:keyword', require('./routes/huxiu/search'));
router.get('/huxiu/author/:id', require('./routes/huxiu/author'));
router.get('/huxiu/article', require('./routes/huxiu/article'));
// Steam
router.get('/steam/search/:params', require('./routes/steam/search'));
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
module.exports = async (ctx) => {
const link = 'https://www.huxiu.com/article';
const response = await got({
method: 'get',
url: link,
headers: {
Referer: link,
},
});
const $ = cheerio.load(response.data);
const list = $('.article-item--normal > a, .article-item--large > a')
.slice(0, 10)
.get()
.map((e) => $(e).attr('href'));
const items = await utils.ProcessFeed(list, ctx.cache);
ctx.state.data = {
title: '虎嗅网 - 首页资讯',
link,
description: '聚合优质的创新信息与人群,捕获精选 | 深度 | 犀利的商业科技资讯。在虎嗅,不错过互联网的每个重要时刻。',
item: items,
};
};
+1 -1
View File
@@ -21,7 +21,7 @@ module.exports = async (ctx) => {
const items = await utils.ProcessFeed(list, ctx.cache);
const info = `虎嗅 - ${$('.tag-title').text()}`;
const info = `虎嗅 - ${$('h1').text()}`;
ctx.state.data = {
title: info,
link,
+8 -2
View File
@@ -15,13 +15,19 @@ const ProcessFeed = async (list, cache) => {
const $ = cheerio.load(response.data);
$('.article__content')
.find('.lazyImg')
.each((i, e) => {
$(e).attr('src', $(e).attr('_src'));
});
return {
title: $('.article__title')
.text()
.trim(),
description: $('.article__top-img-video') + $('.article__content').html(),
pubDate: date($('.article__bottom-content__right .article__time').text(), 8),
author: $('.article__author-info-box .author-info__username').text(),
pubDate: date($('.article__time').text(), 8),
author: $('.author-info__username').text(),
link,
};
});