From 03a00cde69dad1c88040bdbc1307624bb11bc228 Mon Sep 17 00:00:00 2001 From: valuex Date: Sat, 5 Oct 2024 00:03:32 +0900 Subject: [PATCH] feat(route): add Resonac (#16960) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create namespace.ts * Add files via upload * Update dongtai.ts * Update gonggao.ts * Update gonggao.ts * Update gonggao.ts * Update dongtai.ts * Update gonggao.ts * Update gonggao.ts * Update gonggao.ts * Update gonggao.ts * Update dongtai.ts * Create namespace.ts * Add files via upload * Update articles.ts * Update articles.ts * Update articles.ts * Update articles.ts * Update articles.ts * Update articles.ts * Update articles.ts * route for 日经新闻半导体,产业聚焦 * Update scienceatechnology.ts * Update semi.ts * Delete lib/routes/yamap directory * Delete lib/routes/nikkei/semi.ts * Delete lib/routes/nikkei/scienceatechnology.ts * Update lib/routes/szftedu/dongtai.ts Co-authored-by: Tony * Update lib/routes/szftedu/namespace.ts Co-authored-by: Tony * Update lib/routes/szftedu/gonggao.ts Co-authored-by: Tony * Update gonggao.ts * Update gonggao.ts * Update dongtai.ts * Update gonggao.ts * Update gonggao.ts * Update dongtai.ts * Update dongtai.ts * Update dongtai.ts * Update gonggao.ts * Update lib/routes/szftedu/gonggao.ts Co-authored-by: Tony * Update lib/routes/szftedu/dongtai.ts Co-authored-by: Tony * Update dongtai.ts * Update dongtai.ts * fix: route name * new route: resonac products * Update products.ts * Update products.ts * Update products.ts * Update products.ts * fix: names * fix: remove fake pubDate * fix: remove unecessary spaces in selectors * fix: selectors --------- --- lib/routes/resonac/namespace.ts | 6 +++ lib/routes/resonac/products.ts | 85 +++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 lib/routes/resonac/namespace.ts create mode 100644 lib/routes/resonac/products.ts diff --git a/lib/routes/resonac/namespace.ts b/lib/routes/resonac/namespace.ts new file mode 100644 index 0000000000000..8be80f945f49d --- /dev/null +++ b/lib/routes/resonac/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Resonac', + url: 'www.resonac.com', +}; diff --git a/lib/routes/resonac/products.ts b/lib/routes/resonac/products.ts new file mode 100644 index 0000000000000..918c8b79ea493 --- /dev/null +++ b/lib/routes/resonac/products.ts @@ -0,0 +1,85 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +// import { parseDate } from '@/utils/parse-date'; +// import timezone from '@/utils/timezone'; + +const baseUrl = 'https://www.resonac.com'; +const host = 'https://www.resonac.com/products?intcid=glnavi_products'; + +export const route: Route = { + path: '/products', + categories: ['other'], + example: '/resonac/products', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: true, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: 'Products', + maintainers: ['valuex'], + handler, + description: '', +}; + +async function handler() { + const response = await got(host); + const pageHtml = response.data; + const $ = load(pageHtml); + const groupLists = $('div.m-panel-card-link ul li') + .toArray() + .map((el) => ({ + groupName: $('a', el).text().trim(), + groupURL: baseUrl + $('a', el).attr('href'), + })); + + const lists = await Promise.all( + groupLists.map((productGroup) => + cache.tryGet(productGroup.groupURL, async () => { + const strUrl = productGroup.groupURL; + const response = await got(strUrl); + const $ = load(response.data); + const item = $('dt.m-toggle__title div span a') + .toArray() + .map((el) => ({ + title: $('b', el).text().trim(), + link: baseUrl + $(el).attr('href'), + group: productGroup.groupName, + })); + return item; + }) + ) + ); + + const fullList = lists.flat(1); // flatten array + // fullList = fullList.filter((item) => item.title !== 'Empty'); + + const items = await Promise.all( + fullList.map((item) => + cache.tryGet(item.link, async () => { + try { + const response = await got(item.link); + const $ = load(response.data); + const thisTitle = item.title + ' | ' + item.group; + item.title = thisTitle; + item.description = $('main div.str-section').html(); + return item; + } catch (error) { + return (error as Error).message; + } + }) + ) + ); + + return { + title: 'Resonac_Products', + link: baseUrl, + description: 'Resonac_Products', + item: items, + }; +}