mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
test rss? and made some more files.
This commit is contained in:
parent
569cd087e7
commit
5f897f1bd0
13 changed files with 132 additions and 2 deletions
28
server/api/rss/google.ts
Normal file
28
server/api/rss/google.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import Parser from 'rss-parser'
|
||||
import { HTMLToJSON } from 'html-to-json-parser';
|
||||
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
let array = [];
|
||||
const parser = new Parser()
|
||||
try {
|
||||
const feed = await parser.parseURL('https://news.google.com/rss?&hl=zh-TW&gl=TW&ceid=TW:zh-Hant')
|
||||
feed.items.forEach(async (item) => {
|
||||
const relatedNews = JSON.parse(await HTMLToJSON(item.content, true))
|
||||
array.push({
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
date: item.pubDate,
|
||||
relatedNews: relatedNews
|
||||
});
|
||||
console.log(item.title);
|
||||
})
|
||||
return array;
|
||||
} catch (error) {
|
||||
console.error('Error fetching RSS:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: 'Failed to fetch RSS feed'
|
||||
})
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue