newsnow/server/sources/gelonghui.ts

32 lines
968 B
TypeScript
Raw Permalink Normal View History

2024-10-21 03:05:50 +08:00
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
export default defineSource(async () => {
const baseURL = "https://www.gelonghui.com"
const html: any = await myFetch("https://www.gelonghui.com/news/")
2024-10-21 03:05:50 +08:00
const $ = cheerio.load(html)
const $main = $(".article-content")
const news: NewsItem[] = []
$main.each((_, el) => {
const a = $(el).find(".detail-right>a")
// https://www.kzaobao.com/shiju/20241002/170659.html
const url = a.attr("href")
const title = a.find("h2").text()
2024-10-21 17:00:51 +08:00
const info = $(el).find(".time > span:nth-child(1)").text()
2024-10-21 03:05:50 +08:00
// 第三个 p
const relatieveTime = $(el).find(".time > span:nth-child(3)").text()
if (url && title && relatieveTime) {
news.push({
url: baseURL + url,
title,
id: url,
extra: {
2024-10-27 22:09:17 +08:00
date: parseRelativeDate(relatieveTime, "Asia/Shanghai").valueOf(),
2024-10-21 03:05:50 +08:00
info,
},
})
}
})
2024-10-21 17:00:51 +08:00
return news
2024-10-21 03:05:50 +08:00
})