mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Archive the jssoup one for now
This commit is contained in:
parent
5f78e8c58a
commit
0bcb646cc0
4 changed files with 45 additions and 19 deletions
|
@ -1,20 +1,7 @@
|
|||
import lineToday from "~/server/scrape/line_today";
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
return new Promise((resolve, reject) => {
|
||||
const pythonProcess = spawn("python3", ["scraping/hot_articles.py"]);
|
||||
|
||||
let dataString = "";
|
||||
|
||||
pythonProcess.stdout.on("data", (data) => {
|
||||
dataString += data.toString();
|
||||
});
|
||||
|
||||
pythonProcess.stderr.on("data", (data) => {
|
||||
console.error(`Error: ${data}`);
|
||||
});
|
||||
|
||||
pythonProcess.on("close", (code) => {
|
||||
resolve({ status: "completed", output: dataString });
|
||||
});
|
||||
});
|
||||
const data = await lineToday(slug);
|
||||
console.log(data);
|
||||
return data;
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import JSSoup from "jssoup";
|
||||
//import cheerio from "cheerio";
|
||||
|
||||
async function lineToday(slug: string) {
|
||||
const url = "https://today.line.me/tw/v2/article/" + slug;
|
||||
|
@ -16,8 +17,20 @@ async function lineToday(slug: string) {
|
|||
"Cache-Control": "max-age=0",
|
||||
},
|
||||
});
|
||||
const data = fetchPageCode.text();
|
||||
const soup = new JSSoup(data);
|
||||
// 幹 又忘了 await
|
||||
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 article = soup.find("article", "news-content");
|
||||
const paragraph = article.text;
|
||||
return {
|
||||
title: title,
|
||||
paragraph: paragraph,
|
||||
};
|
||||
}
|
||||
|
||||
export default lineToday;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue