mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
A publisher api. & modded the news.vue file to use the publisherId instead of the name. & cleaned the code using prettier.
This commit is contained in:
parent
1dd324e0ca
commit
5392974261
6 changed files with 99 additions and 36 deletions
|
@ -1,9 +1,48 @@
|
|||
import * as cheerio from "cheerio";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const buildUrl = "https://today.line.me/tw/v3/publisher/" + slug;
|
||||
try {
|
||||
const req = await fetch(buildUrl)
|
||||
} catch (e) {}
|
||||
})
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const buildUrl = "https://today.line.me/tw/v3/publisher/" + slug;
|
||||
try {
|
||||
const req = await fetch(buildUrl, {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||
Accept: "*",
|
||||
"Accept-Language": "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
Connection: "keep-alive",
|
||||
"Sec-Fetch-Dest": "document",
|
||||
"Sec-Fetch-Mode": "navigate",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"Cache-Control": "max-age=0",
|
||||
},
|
||||
});
|
||||
const data = await req.text();
|
||||
const html = cheerio.load(data);
|
||||
const newsOrgName = html("div.profileHead")
|
||||
.text()
|
||||
.replace(/.css-.*\}/, "");
|
||||
const description = html("p.description").text();
|
||||
const logo =
|
||||
html("div.editor div figure img").attr("srcset") ||
|
||||
html("div.editor div figure img").attr("src") ||
|
||||
"";
|
||||
const articles = [];
|
||||
const otherArticles = html("section.moduleContainer div");
|
||||
for (const item in otherArticles) {
|
||||
|
||||
}
|
||||
return {
|
||||
name: newsOrgName,
|
||||
description: description,
|
||||
logo: logo,
|
||||
articles: []
|
||||
};
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return {
|
||||
error: "SERVER_SIDE_ERROR",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue