The Line Today scaper finally WORKS!! Now we just need make a UI for

it...
This commit is contained in:
吳元皓 2025-05-18 11:13:25 +08:00
parent 0bcb646cc0
commit fe5e2d996e
2 changed files with 7 additions and 8 deletions

View File

@ -2,6 +2,5 @@ import lineToday from "~/server/scrape/line_today";
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const slug = getRouterParam(event, "slug"); const slug = getRouterParam(event, "slug");
const data = await lineToday(slug); const data = await lineToday(slug);
console.log(data);
return data; return data;
}); });

View File

@ -1,5 +1,4 @@
import JSSoup from "jssoup"; import * as cheerio from "cheerio";
//import cheerio from "cheerio";
async function lineToday(slug: string) { async function lineToday(slug: string) {
const url = "https://today.line.me/tw/v2/article/" + slug; const url = "https://today.line.me/tw/v2/article/" + slug;
@ -21,16 +20,17 @@ async function lineToday(slug: string) {
const data = await fetchPageCode.text(); const data = await fetchPageCode.text();
// 加 await? no. // 加 await? no.
// AHHH I NEED TO CHANGE TO SOMETHING ELSE. // AHHH I NEED TO CHANGE TO SOMETHING ELSE.
const soup = new JSSoup(data, false); const html = cheerio.load(data);
const titlesoup = soup.find("h1", "entityTitle"); const title = html("h1.entityTitle").text().replaceAll("\n", "");
const title = titlesoup.text.replaceAll("\n", "");
const article = soup.find("article", "news-content"); const paragraph = html("article.news-content").text();
const paragraph = article.text;
return { return {
title: title, title: title,
paragraph: paragraph, paragraph: paragraph,
}; };
} }
// Texting on console only!
//console.log(await lineToday("oqmazXP"));
export default lineToday; export default lineToday;