diff --git a/lib/routes/fortunechina/index.ts b/lib/routes/fortunechina/index.ts index 43540e4eff1c70..dae10e6a13d8e4 100644 --- a/lib/routes/fortunechina/index.ts +++ b/lib/routes/fortunechina/index.ts @@ -1,8 +1,11 @@ import { Route } from '@/types'; import cache from '@/utils/cache'; -import got from '@/utils/got'; +import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { parseDate, parseRelativeDate } from '@/utils/parse-date'; +import randUserAgent from '@/utils/rand-user-agent'; + +const UA = randUserAgent({ browser: 'mobile safari', os: 'ios', device: 'mobile' }); export const route: Route = { path: '/:category?', @@ -36,15 +39,12 @@ async function handler(ctx) { const rootUrl = 'https://www.fortunechina.com'; const currentUrl = `${rootUrl}${category ? `/${category}` : ''}`; - const response = await got({ - method: 'get', - url: currentUrl, - }); + const response = await ofetch(currentUrl); - const $ = load(response.data); + const $ = load(response); let items = $('.main') - .find('h3 a') + .find(category === '' ? 'a:has(h2)' : 'h2 a') .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15) .toArray() .map((item) => { @@ -61,14 +61,15 @@ async function handler(ctx) { items = await Promise.all( items.map((item) => cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, + const detailResponse = await ofetch(item.link, { + headers: { + 'User-Agent': UA, + } }); - const content = load(detailResponse.data); + const content = load(detailResponse); - const spans = content('.mod-info span').text(); + const spans = content('.date').text(); let matches = spans.match(/(\d{4}-\d{2}-\d{2})/); if (matches) { item.pubDate = parseDate(matches[1]); @@ -79,11 +80,22 @@ async function handler(ctx) { } } - item.author = content('.name').text(); + item.author = content('.author').text(); content('.mod-info, .title, .eval-zan, .eval-pic, .sae-more, .ugo-kol, .word-text .word-box .word-cn').remove(); - item.description = content('#articleContent, .eval-desc').html(); + item.description = content(item.link.includes('content') ? '.contain .text' : '.contain .top').html(); + if (item.link.includes('jingxuan')) { + item.description += content('.eval-mod_ugo').html(); + } + else if (item.link.includes('events')) { + const eventDetails = await ofetch(`https://www.bagevent.com/event/${item.link.match(/\d+/)[0]}`); + const $event = load(eventDetails); + item.description = $event(".page_con").html(); + } + else if (item.link.includes('zhuanlan')) { + item.description += content('.mod-word').html(); + } return item; })