fix(route): cnbeta (#13714)
This commit is contained in:
parent
b1f2be63ce
commit
125c24eb97
|
|
@ -15,18 +15,24 @@ module.exports = async (ctx) => {
|
||||||
const $ = cheerio.load(response.data);
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
const token = encodeURI($('meta[name="csrf-token"]').attr('content'));
|
const token = encodeURI($('meta[name="csrf-token"]').attr('content'));
|
||||||
const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').attr('data-type')}&page=1&_csrf=${token}&_=${new Date().getTime()}`;
|
const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').data('type')}&page=1&_csrf=${token}&_=${Date.now()}`;
|
||||||
|
|
||||||
response = await got(apiUrl);
|
response = await got(apiUrl);
|
||||||
|
|
||||||
const items = response.data.result.list.map((item) => ({
|
const items = type
|
||||||
title: item.title,
|
? response.data.result.list.map((item) => ({
|
||||||
description: item.hometext,
|
title: item.title,
|
||||||
author: item.source.split('@http')[0],
|
description: item.hometext,
|
||||||
pubDate: timezone(parseDate(item.inputtime), +8),
|
author: item.source.split('@http')[0],
|
||||||
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
pubDate: timezone(parseDate(item.inputtime), +8),
|
||||||
category: item.label.name,
|
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
||||||
}));
|
category: item.label.name,
|
||||||
|
}))
|
||||||
|
: response.data.result.map((item) => ({
|
||||||
|
title: item.title,
|
||||||
|
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
||||||
|
category: item.label.name,
|
||||||
|
}));
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
title: $('title').text(),
|
title: $('title').text(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
const got = require('@/utils/got');
|
const got = require('@/utils/got');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
const timezone = require('@/utils/timezone');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
|
||||||
const rootUrl = 'https://www.cnbeta.com.tw';
|
const rootUrl = 'https://www.cnbeta.com.tw';
|
||||||
|
|
||||||
|
|
@ -17,6 +19,7 @@ module.exports = {
|
||||||
|
|
||||||
item.description = content('.article-summary').html() + content('.article-content').html();
|
item.description = content('.article-summary').html() + content('.article-content').html();
|
||||||
item.author = content('header.title div.meta span.source').text();
|
item.author = content('header.title div.meta span.source').text();
|
||||||
|
item.pubDate ??= timezone(parseDate(content('.meta span').first().text(), 'YYYY年MM月DD日 HH:mm'), +8);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue