mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
fix: link bug and add docs keywords (#2398)
This commit is contained in:
@@ -16,7 +16,7 @@ pageClass: routes
|
||||
|
||||
<Route author="xyqfer" example="/36kr/search/article/8%E7%82%B91%E6%B0%AA" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
|
||||
## 7x24 小时快讯
|
||||
## 汇通网
|
||||
|
||||
### 7x24 小时快讯
|
||||
|
||||
|
||||
@@ -1,34 +1,44 @@
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const url = require('url');
|
||||
const host = 'https://kx.fx678.com/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://kx.fx678.com/';
|
||||
const res = await got.get(url);
|
||||
const link = 'https://kx.fx678.com/';
|
||||
const res = await got.get(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const list = $('.body_zb ul .body_zb_li');
|
||||
// 爬取页面的前30条消息
|
||||
const content = list
|
||||
// 页面新闻消息列表
|
||||
const list = $('.body_zb ul .body_zb_li .zb_word')
|
||||
.find('.list_font_pic > a:first-child')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.slice(0, 30)
|
||||
.map(function() {
|
||||
const title = $(this)
|
||||
.find('.zb_time')
|
||||
.text();
|
||||
const description = $(this)
|
||||
.find('.zb_word')
|
||||
.text()
|
||||
.replace(/(^\s*)|(\s*$)/g, '');
|
||||
const item = {
|
||||
title,
|
||||
description,
|
||||
};
|
||||
return item;
|
||||
})
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl) => {
|
||||
const absoluteUrl = url.resolve(host, itemUrl);
|
||||
const cache = await ctx.cache.get(absoluteUrl);
|
||||
// 判断缓存
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const res = await got.get(absoluteUrl);
|
||||
const $ = cheerio.load(res.data);
|
||||
|
||||
const item = {
|
||||
title: $('.article-cont h1').text(),
|
||||
link: absoluteUrl,
|
||||
description: $('.article-main .content').html(),
|
||||
pubDate: new Date().toUTCString(),
|
||||
};
|
||||
ctx.cache.set(absoluteUrl, JSON.stringify(item));
|
||||
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: '7x24小时快讯',
|
||||
link: url,
|
||||
item: content,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user