mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
The Line Today scaper finally WORKS!! Now we just need make a UI for
it...
This commit is contained in:
parent
0bcb646cc0
commit
fe5e2d996e
2 changed files with 7 additions and 8 deletions
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue