From fe5e2d996eaafb2acd2bcc0b3891ccfbfd8315fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Sun, 18 May 2025 11:13:25 +0800 Subject: [PATCH] The Line Today scaper finally WORKS!! Now we just need make a UI for it... --- server/api/news/get/lt/[slug].ts | 1 - server/scrape/line_today.ts | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/api/news/get/lt/[slug].ts b/server/api/news/get/lt/[slug].ts index 1e277fd..329c8be 100644 --- a/server/api/news/get/lt/[slug].ts +++ b/server/api/news/get/lt/[slug].ts @@ -2,6 +2,5 @@ import lineToday from "~/server/scrape/line_today"; export default defineEventHandler(async (event) => { const slug = getRouterParam(event, "slug"); const data = await lineToday(slug); - console.log(data); return data; }); diff --git a/server/scrape/line_today.ts b/server/scrape/line_today.ts index c3bf189..f10bdd9 100644 --- a/server/scrape/line_today.ts +++ b/server/scrape/line_today.ts @@ -1,5 +1,4 @@ -import JSSoup from "jssoup"; -//import cheerio from "cheerio"; +import * as cheerio from "cheerio"; async function lineToday(slug: string) { const url = "https://today.line.me/tw/v2/article/" + slug; @@ -21,16 +20,17 @@ async function lineToday(slug: string) { const data = await fetchPageCode.text(); // 加 await? no. // AHHH I NEED TO CHANGE TO SOMETHING ELSE. - const soup = new JSSoup(data, false); - const titlesoup = soup.find("h1", "entityTitle"); - const title = titlesoup.text.replaceAll("\n", ""); + const html = cheerio.load(data); + const title = html("h1.entityTitle").text().replaceAll("\n", ""); - const article = soup.find("article", "news-content"); - const paragraph = article.text; + const paragraph = html("article.news-content").text(); return { title: title, paragraph: paragraph, }; } +// Texting on console only! +//console.log(await lineToday("oqmazXP")); + export default lineToday;