From f62f12da1cc58e636b801dc3d84979ec0a9da305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=B5=A9=E5=AE=87?= <37102468+HaoyuLee@users.noreply.github.com> Date: Thu, 25 Apr 2024 20:18:02 +0800 Subject: [PATCH] feat: add route /gov/zj/search/:websiteid?/:word/:cateid? (#15359) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 浙江省人民政府-统一搜索结果 * refactor: 浙江省人民政府-统一搜索结果-代码规范修正、description字段补充 * Update lib/routes/gov/zj/search.ts Co-authored-by: Tony * Update lib/routes/gov/zj/search.ts Co-authored-by: Tony * Update lib/routes/gov/zj/search.ts Co-authored-by: Tony --------- Co-authored-by: lihaoyu --- lib/routes/gov/zj/search.ts | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lib/routes/gov/zj/search.ts diff --git a/lib/routes/gov/zj/search.ts b/lib/routes/gov/zj/search.ts new file mode 100644 index 00000000000000..37dc20fc63fb18 --- /dev/null +++ b/lib/routes/gov/zj/search.ts @@ -0,0 +1,78 @@ +import { Route } from '@/types'; +import { parseDate } from '@/utils/parse-date'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import dayjs from 'dayjs'; + +export const route: Route = { + path: '/zj/search/:websiteid?/:word/:cateid?', + categories: ['government'], + example: '/gov/zj/search', + parameters: { + websiteid: '搜索范围-全省、各市各区、详细信息点击源网站https://www.zj.gov.cn/请求中寻找', + word: '搜索关键词-默认:人才', + cateid: '信息分类-默认:658(全部)', + sortType: '排序类型-默认:2(按时间)', + }, + radar: [{ + source: ['search.zj.gov.cn/jsearchfront/search.do'], + target: '/zj/search/:websiteid?/:word/:cateid?', + }], + name: '浙江省人民政府-全省政府网站统一搜索', + url: 'search.zj.gov.cn/jsearchfront/search.do', + maintainers: ['HaoyuLee'], + description: ` + | 行政区域 | websiteid | + | ------------ | -- | + | 宁波市本级 | 330201000000000 | + + | 搜索关键词 | word | + + | 信息分类 | cateid | + + | 排序类型 | sortType | + | ------------ | -- | + | 按相关度 | 1 | + | 按时间 | 2 | + `, + async handler(ctx) { + const { websiteid = '330201000000000', word = '人才', cateid = 658, sortType = 2 } = ctx.req.param(); + const { + data: { result: list }, + } = await got.post('https://search.zj.gov.cn/jsearchfront/interfaces/cateSearch.do', { + form: { + websiteid, + pg: '30', + p: '1', + cateid, + word, + checkError: 1, + isContains: 0, + q: word, + begin: dayjs().subtract(1, 'week').format('YYYYMMDD'), + end: dayjs().format('YYYYMMDD'), + timetype: 2, + pos: 'title,content,keyword', + sortType, + }, + }); + const items = + list?.map((item: string) => { + const $ = load(item); + const title = $('.titleWrapper>a'); + const footer = $('.sourceTime>span'); + return { + title: title.text().trim() || '', + link: title.attr('href') || '', + pubDate: parseDate(footer.eq(1).text().trim().replace('时间:', '')) || '', + author: footer.eq(0).text().trim().replace('来源:', '') || '', + description: $('.newsDescribe>a').text() || '', + }; + }) || []; + return { + title: '浙江省人民政府-全省政府网站统一搜索', + link: 'https://search.zj.gov.cn/jsearchfront/search.do', + item: items, + }; + }, +};