fix(route): 爱 Q 生活网 最近更新内容获取 (#12284)

* fix url and response

* refactor: migrate to v2

---------
This commit is contained in:
egshuai 2023-04-12 22:45:15 +08:00 committed by GitHub
parent 24c2dc5d66
commit b2ace34670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 15 deletions

View File

@ -422,7 +422,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 最近更新
<Route author="nczitzk" example="/3k8/latest" path="/3k8/latest"/>
<Route author="nczitzk" example="/iqnew/latest" path="/iqnew/latest" radar="1"/>
## 爱发电

View File

@ -3083,8 +3083,8 @@ router.get('/nasa/apod-ncku', lazyloadRouteHandler('./routes/nasa/apod-ncku'));
router.get('/nasa/apod-cn', lazyloadRouteHandler('./routes/nasa/apod-cn'));
// 爱Q生活网
router.get('/iqshw/latest', lazyloadRouteHandler('./routes/3k8/latest'));
router.get('/3k8/latest', lazyloadRouteHandler('./routes/3k8/latest'));
// router.get('/iqshw/latest', lazyloadRouteHandler('./routes/3k8/latest'));
// router.get('/3k8/latest', lazyloadRouteHandler('./routes/3k8/latest'));
// JustRun
router.get('/justrun', lazyloadRouteHandler('./routes/justrun/index'));

View File

@ -1,26 +1,29 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const rootUrl = 'https://wap.3k8.com';
const rootUrl = 'https://www.iqnew.com';
const url = rootUrl + '/post/new_100/';
const response = await got({
method: 'get',
url: rootUrl,
url,
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
const list = $('div.one-img-plc')
.slice(0, 10)
.map((_, item) => {
const list = $('.page-main-list .list-item a')
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 50)
.toArray()
.map((item) => {
item = $(item);
return {
link: rootUrl + item.find('a').attr('href'),
link: rootUrl + item.attr('href'),
};
})
.get();
});
const items = await Promise.all(
list.map((item) =>
@ -33,9 +36,13 @@ module.exports = async (ctx) => {
const content = cheerio.load(iconv.decode(detailResponse.data, 'gb2312'));
item.title = content('h1.title').text();
item.pubDate = new Date(content('div.news-mes span').eq(0).text().replace('发布时间:', '').trim() + ' GMT+8').toUTCString();
item.description = content('div.news-content').html();
item.title = content('.main-article .title').text();
item.pubDate = timezone(parseDate(content('.time').eq(0).text()), 8);
item.description = content('.content-intro').html();
item.author = content('.author a').text();
item.category = content('.keyword > a')
.toArray()
.map((item) => $(item).text());
return item;
})
@ -44,7 +51,7 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '爱Q生活网 - 最近更新',
link: rootUrl,
link: url,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/latest': ['nczitzk'],
};

13
lib/v2/iqnew/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'iqnew.com': {
_name: '爱 Q 生活网',
'.': [
{
title: '最近更新',
docs: 'https://docs.rsshub.app/others.html#ai-q-sheng-huo-wang',
source: ['/post/new_100/', '/'],
target: '/iqnew/latest',
},
],
},
};

3
lib/v2/iqnew/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/latest', require('./latest'));
};