From 165eb41d5d7855ab1442e5db04a0ae5fa47c5643 Mon Sep 17 00:00:00 2001 From: JianLinWei1 <319720040@qq.com> Date: Fri, 1 Nov 2024 11:01:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(route):=E6=96=B0=E5=A2=9E=E6=96=B0?= =?UTF-8?q?=E6=B5=AA=E9=BB=91=E7=8C=AB=E6=8A=95=E8=AF=89=E7=83=AD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/sina/tousu.ts | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/routes/sina/tousu.ts diff --git a/lib/routes/sina/tousu.ts b/lib/routes/sina/tousu.ts new file mode 100644 index 00000000000000..b1ded4fb01f531 --- /dev/null +++ b/lib/routes/sina/tousu.ts @@ -0,0 +1,65 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +import logger from '@/utils/logger'; +import puppeteer from '@/utils/puppeteer'; +import { load } from 'cheerio'; + +export const route: Route = { + path: '/tousu', + name: '黑猫投诉', + url: 'tousu.sina.com.cn', + example: '/sina/tousu', + maintainers: ['JianLinWei1'], + radar: [ + { + source: ['tousu.sina.com.cn'], + }, + ], + handler, + +} + + +async function handler(ctx) { + + const browser = await puppeteer(); + + const page = await browser.newPage(); + + const link = 'https://tousu.sina.cn'; + + logger.http(`Requesting ${link}`); + await page.goto(link, { + + waitUntil: 'networkidle2', + }); + + const response = await page.content(); + + page.close(); + const $ = load(response); + const blackcatCons = $('div.blackcat-con').toArray(); + const items = blackcatCons.map((item) => { + const title = $(item).find('h1.blackcat-hot').text() + const link = $(item).find('a.box').attr('href') + const description = $(item).find('p').text() + $(item).find('ul.list').text() + const author = $(item).find('span.name').text() + return { + title: title, + link: link, + description: description, + author: author, + } + }) + return { + title: `黑猫投诉-新浪旗下消费者服务平台`, + link: `https://tousu.sina.cn`, + description: `feedId:74988831961543680+userId:74002328552935424`, + item: items, + }; + + + +} \ No newline at end of file From 958709c398c7c65ac10711f15173e4b52d961d2c Mon Sep 17 00:00:00 2001 From: JianLinWei1 <319720040@qq.com> Date: Thu, 7 Nov 2024 16:22:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(route):=E6=96=B0=E5=A2=9E=E6=96=B0?= =?UTF-8?q?=E6=B5=AA=E9=BB=91=E7=8C=AB=E6=8A=95=E8=AF=89=E7=83=AD=E7=82=B9?= =?UTF-8?q?=E6=8A=95=E8=AF=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/sina/tousu.ts | 46 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/lib/routes/sina/tousu.ts b/lib/routes/sina/tousu.ts index b1ded4fb01f531..c69d1052d90971 100644 --- a/lib/routes/sina/tousu.ts +++ b/lib/routes/sina/tousu.ts @@ -1,6 +1,10 @@ +/* + * @Descripttion: description + * @Author: -0V + * @Date: 2024-11-01 10:59:51 + * @LastEditTime: 2024-11-07 16:11:14 + */ import { Route } from '@/types'; -import ofetch from '@/utils/ofetch'; -import { parseDate } from '@/utils/parse-date'; import logger from '@/utils/logger'; import puppeteer from '@/utils/puppeteer'; @@ -18,48 +22,36 @@ export const route: Route = { }, ], handler, +}; -} - - -async function handler(ctx) { - +async function handler() { const browser = await puppeteer(); - const page = await browser.newPage(); - const link = 'https://tousu.sina.cn'; - logger.http(`Requesting ${link}`); await page.goto(link, { - waitUntil: 'networkidle2', }); - const response = await page.content(); - page.close(); const $ = load(response); const blackcatCons = $('div.blackcat-con').toArray(); const items = blackcatCons.map((item) => { - const title = $(item).find('h1.blackcat-hot').text() - const link = $(item).find('a.box').attr('href') - const description = $(item).find('p').text() + $(item).find('ul.list').text() - const author = $(item).find('span.name').text() + const title = $(item).find('h1.blackcat-hot').text(); + const link = $(item).find('a.box').attr('href'); + const description = $(item).find('p').text() + $(item).find('ul.list').text(); + const author = $(item).find('span.name').text(); return { - title: title, - link: link, - description: description, - author: author, - } - }) + title, + link, + description, + author, + }; + }); return { title: `黑猫投诉-新浪旗下消费者服务平台`, link: `https://tousu.sina.cn`, description: `feedId:74988831961543680+userId:74002328552935424`, item: items, }; - - - -} \ No newline at end of file +}