feat(route): add 杭州市人民政府 (#18208)

* feat(route): add 杭州市人民政府

* change maintainer username

* perf: drop unnecessary requests

* feat: use art-template to format content from 浙江政务服务网

* fix: remove custom UA

* fix: puppeteer timeout due to unnecessary  page request, turn off page interception

* perf: reduce loading time & fix(puppeteer): exceed waitForSelector timeout
This commit is contained in:
Majimay
2025-04-01 19:09:46 +08:00
committed by GitHub
parent fd5cc6868f
commit a4935ea1ac
4 changed files with 383 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: "Hangzhou People's Government",
url: 'hangzhou.gov.cn',
zh: {
name: '杭州市人民政府',
},
};
+173
View File
@@ -0,0 +1,173 @@
<table>
<tbody>
<tr>
<th colspan="4">办事信息</th>
</tr>
<tr>
<th>服务对象</th>
<td>{{serviceInfo.serviceTarget}}</td>
<th>办理形式</th>
<td>{{serviceInfo.processingMethods}}</td>
</tr>
<tr>
<th>办理地点</th>
<td colspan="3">{{serviceInfo.processingLocation}}</td>
</tr>
<tr>
<th>办理时间</th>
<td colspan="3">{{serviceInfo.processingTime}}</td>
</tr>
<tr>
<th colspan="4">申请信息</th>
</tr>
<tr>
<th>受理条件</th>
<td colspan="3">{{applicationInfo.acceptanceConditions}}</td>
</tr>
<tr>
<th>禁止性要求</th>
<td colspan="3">{{applicationInfo.prohibitedRequirements}}</td>
</tr>
<tr>
<th>数量限制</th>
<td colspan="3">{{applicationInfo.quantityRestrictions}}</td>
</tr>
<tr>
<th colspan="4">结果信息</th>
</tr>
<tr>
<th>审批结果名称</th>
<td colspan="3">{{resultInfo.approvalResult}}</td>
</tr>
<tr>
<th>审批结果样本</th>
<td>{{@ resultInfo.approvalSample }}</td>
<th>审批结果类型</th>
<td>{{resultInfo.approvalResultType}}</td>
</tr>
<tr>
<th colspan="4">收费信息</th>
</tr>
<tr>
<th>是否收费</th>
<td>{{feeInfo.isThereAFee}}</td>
<th>是否支持网上支付</th>
<td>{{feeInfo.isOnlinePaymentSupported}}</td>
</tr>
<tr>
<th colspan="4">审批信息</th>
</tr>
<tr>
<th>权力来源</th>
<td colspan="3">{{approvalInfo.authoritySource}}</td>
</tr>
<tr>
<th>行使层级</th>
<td>{{approvalInfo.exerciseLevel}}</td>
<th>实施主体性质</th>
<td>{{approvalInfo.implementingEntity}}</td>
</tr>
<tr>
<th colspan="4">送达信息</th>
</tr>
<tr>
<th>是否支持物流快递</th>
<td>{{deliveryInfo.isLogisticsSupported}}</td>
<th>送达时限</th>
<td>{{deliveryInfo.deliveryTimeframe}}</td>
</tr>
<tr>
<th>送达方式</th>
<td colspan="3">{{deliveryInfo.deliveryMethods}}</td>
</tr>
<tr>
<th colspan="4">中介服务信息</th>
</tr>
<tr>
<th>中介服务事项名称</th>
<td colspan="3">{{agentService}}</td>
</tr>
<tr>
<th colspan="4">其他信息</th>
</tr>
<tr>
<th>部门名称</th>
<td>{{otherInfo.departmentName}}</td>
<th>事项类型</th>
<td>{{otherInfo.matterType}}</td>
</tr>
<tr>
<th>受理机构</th>
<td colspan="3">{{otherInfo.acceptingInstitution}}</td>
</tr>
<tr>
<th>基本编码</th>
<td>{{otherInfo.basicCode}}</td>
<th>实施编码</th>
<td>{{otherInfo.implementationCode}}</td>
</tr>
<tr>
<th>通办范围</th>
<td>{{otherInfo.scopeOfGeneralHandling}}</td>
<th>办件类型</th>
<td>{{otherInfo.documentType}}</td>
</tr>
<tr>
<th>决定机构</th>
<td>{{otherInfo.decisionMakingAuthority}}</td>
<th>委托部门</th>
<td>{{otherInfo.delegatedDepartment}}</td>
</tr>
<tr>
<th>网上办理深度</th>
<td>{{otherInfo.onlineProcessingDepth}}</td>
<th>事项审查类型</th>
<td>{{otherInfo.reviewType}}</td>
</tr>
<tr>
<th>是否进驻政务大厅</th>
<td>{{otherInfo.isItAvailableInTheGovernmentServiceHall}}</td>
<th>是否支持自助终端办理</th>
<td>{{otherInfo.isSelfServiceTerminalProcessingSupported}}</td>
</tr>
<tr>
<th>是否实行告知承诺</th>
<td>{{otherInfo.isACommitmentSystemImplemented}}</td>
<th>权力属性</th>
<td>{{otherInfo.authorityAttribute}}</td>
</tr>
<tr>
<th>是否支持预约办理</th>
<td>{{otherInfo.isAppointmentBookingSupported}}</td>
<th>是否网办</th>
<td>{{otherInfo.isOnlineProcessingAvailable}}</td>
</tr>
<tr>
{{ if otherInfo.legalPersonThemeClassification}}
<th>自然人主题分类</th>
<td>{{otherInfo.naturalPersonThemeClassification}}</td>
<th>法人主题分类</th>
<td>{{otherInfo.legalPersonThemeClassification}}</td>
{{ /if }}
{{ if !otherInfo.legalPersonThemeClassification }}
<th>法人主题分类</th>
<td colspan="3">{{otherInfo.naturalPersonThemeClassification}}</td>
{{ /if }}
</tr>
<tr>
<th>行政相对人权利和义务</th>
<td colspan="3">
{{otherInfo.rightsAndObligationsOfAdministrativeCounterparties}}
</td>
</tr>
<tr>
<th>适用对象说明</th>
<td colspan="3">{{otherInfo.applicableObjectDescription}}</td>
</tr>
<tr>
<th>涉及的内容</th>
<td colspan="3">{{otherInfo.contentInvolved}}</td>
</tr>
</tbody>
</table>
+89
View File
@@ -0,0 +1,89 @@
import logger from '@/utils/logger';
export async function crawler(item: any, browser: any): Promise<string> {
try {
let response = '';
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
const resourceType = request.resourceType();
if (['document', 'script', 'stylesheet', 'xhr'].includes(resourceType)) {
request.continue();
} else {
request.abort();
}
});
await page.goto(item.link, {
waitUntil: 'networkidle0',
timeout: 29000,
});
const selector = '.item-left .item .title .button';
await page.evaluate((selector) => document.querySelector(selector).click(), selector);
await page.waitForSelector('.item-left .item .bg_box div:nth-child(16)', { timeout: 5000 });
response = await page.content();
return response || '';
} catch (error) {
logger.error('Error when visiting /gov/hangzhou/zwfw:', error);
return '';
}
}
export function analyzer(box: any): object {
return {
serviceInfo: {
serviceTarget: box.find('.row:nth(1)>div:nth(1)').find('.inner').children().first().attr('content'),
processingMethods: box.find('.row:nth(1)>div:nth(3)').find('.inner').text(),
processingLocation: box.find('.row:nth(2)>div:nth(1)').find('.inner').text(),
processingTime: box.find('.row:nth(3)>div:nth(1)').find('.inner').text(),
},
applicationInfo: {
acceptanceConditions: box.find('.row:nth(5)>div:nth(1)').find('.inner').text(),
prohibitedRequirements: box.find('.row:nth(6)>div:nth(1)').find('.inner').text(),
quantityRestrictions: box.find('.row:nth(7)>div:nth(1)').find('.inner').text(),
},
resultInfo: {
approvalResult: box.find('.row:nth(9)>div:nth(1)').find('.inner').text(),
approvalSample: box.find('.row:nth(10)>div:nth(1)').find('.inner').html(),
approvalResultType: box.find('.row:nth(10)>div:nth(3)').find('.inner').text(),
},
feeInfo: {
isThereAFee: box.find('.row:nth(12)>div:nth(1)').find('.inner').text(),
isOnlinePaymentSupported: box.find('.row:nth(12)>div:nth(3)').find('.inner').text(),
},
approvalInfo: {
authoritySource: box.find('.row:nth(14)>div:nth(1)').find('.inner').text(),
exerciseLevel: box.find('.row:nth(15)>div:nth(1)').find('.inner').text(),
implementingEntity: box.find('.row:nth(15)>div:nth(3)').find('.inner').text(),
},
deliveryInfo: {
isLogisticsSupported: box.find('.row:nth(17)>div:nth(1)').find('.inner').text(),
deliveryTimeframe: box.find('.row:nth(17)>div:nth(3)').find('.inner').text(),
deliveryMethods: box.find('.row:nth(18)>div:nth(1)').find('.inner').text(),
},
agentService: box.find('.row:nth(20)>div:nth(1)').find('.inner').text(),
otherInfo: {
departmentName: box.find('.row:nth(22)>div:nth(1)').find('.inner').text(),
matterType: box.find('.row:nth(22)>div:nth(3)').find('.inner').text(),
acceptingInstitution: box.find('.row:nth(23)>div:nth(1)').find('.inner').text(),
basicCode: box.find('.row:nth(24)>div:nth(1)').find('.inner').text(),
implementationCode: box.find('.row:nth(24)>div:nth(3)').find('.inner').text(),
scopeOfGeneralHandling: box.find('.row:nth(25)>div:nth(1)').find('.inner').text(),
documentType: box.find('.row:nth(25)>div:nth(3)').find('.inner').text(),
decisionMakingAuthority: box.find('.row:nth(26)>div:nth(1)').find('.inner').text(),
delegatedDepartment: box.find('.row:nth(26)>div:nth(3)').find('.inner').text(),
onlineProcessingDepth: box.find('.row:nth(27)>div:nth(1)').find('.inner').text(),
reviewType: box.find('.row:nth(27)>div:nth(3)').find('.inner').text(),
isItAvailableInTheGovernmentServiceHall: box.find('.row:nth(28)>div:nth(1)').find('.inner').text(),
isSelfServiceTerminalProcessingSupported: box.find('.row:nth(28)>div:nth(3)').find('.inner').text(),
isACommitmentSystemImplemented: box.find('.row:nth(29)>div:nth(1)').find('.inner').text(),
authorityAttribute: box.find('.row:nth(29)>div:nth(3)').find('.inner').text(),
isAppointmentBookingSupported: box.find('.row:nth(30)>div:nth(1)').find('.inner').text(),
isOnlineProcessingAvailable: box.find('.row:nth(30)>div:nth(3)').find('.inner').text(),
naturalPersonThemeClassification: box.find('.row:nth(31)>div:nth(1)').find('.inner').text(),
legalPersonThemeClassification: box.find('.row:nth(31)>div:nth(3)').find('.inner').text(),
rightsAndObligationsOfAdministrativeCounterparties: box.find('.row:nth(32)>div:nth(1)').find('.inner').text(),
applicableObjectDescription: box.find('.row:nth(33)>div:nth(1)').find('.inner').text(),
contentInvolved: box.find('.row:nth(34)>div:nth(1)').find('.inner').text(),
},
};
}
+112
View File
@@ -0,0 +1,112 @@
import { Route } from '@/types';
import { load } from 'cheerio';
const __dirname = getCurrentPath(import.meta.url);
import puppeteer from '@/utils/puppeteer';
import ofetch from '@/utils/ofetch';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { crawler, analyzer } from './zjzwfw';
import timezone from '@/utils/timezone';
import path from 'node:path';
import { art } from '@/utils/render';
import { getCurrentPath } from '@/utils/helpers';
export const route: Route = {
path: '/hangzhou/zwfw',
categories: ['government'],
example: '/gov/hangzhou/zwfw',
features: {
requireConfig: false,
requirePuppeteer: true,
antiCrawler: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['hangzhou.gov.cn/col/col1256349/index.html'],
},
],
name: '政务服务公开',
maintainers: ['flynncao'],
handler,
url: 'hangzhou.gov.cn/col/col1256349/index.html',
};
async function handler() {
const host = 'https://www.hangzhou.gov.cn/col/col1256349/index.html';
const response = await ofetch(host);
const browser = await puppeteer({ stealth: true });
const link = host;
const formatted = response
.replace('<script type="text/xml">', '')
.replace('</script>', '')
.replaceAll('<recordset>', '')
.replaceAll('</recordset>', '')
.replaceAll('<record>', '')
.replaceAll('</record>', '')
.replaceAll('<![CDATA[', '')
.replaceAll(']]>', '');
const $ = load(formatted);
const list = $('li.clearfix')
.toArray()
.map((item: any) => {
item = $(item);
const title = item.find('a').first().text();
const time = timezone(parseDate(item.find('span').first().text(), 'YYYY-MM-DD'), 8);
const a = item.find('a').first().attr('href');
const fullUrl = new URL(a, host).href;
return {
title,
link: fullUrl,
pubDate: time,
};
})
.filter((item) => !item.title.includes('置顶'));
const items: any = await Promise.all(
list.map((item: any) =>
cache.tryGet(item.link, async () => {
const host = new URL(item.link).hostname;
if (host === 'www.zjzwfw.gov.cn') {
// 来源为浙江政务服务网
const content = await crawler(item, browser);
const $ = load(content);
item.description = art(path.resolve(__dirname, 'templates/jbxx.art'), analyzer($('.item-left .item .bg_box')));
item.author = '浙江政务服务网';
item.category = $('meta[name="ColumnType"]').attr('content');
} else {
// 其他正常抓取
const response = await got(item.link);
const $ = load(response.data);
if (host === 'police.hangzhou.gov.cn') {
// 来源为杭州市公安局
item.description = $('.art-content .wz_con_content').html();
item.author = $('meta[name="ContentSource"]').attr('content');
item.category = $('meta[name="ColumnType"]').attr('content');
} else {
// 缺省:来源为杭州市政府网
item.description = $('.article').html();
item.author = $('meta[name="ContentSource"]').attr('content');
item.category = $('meta[name="ColumnType"]').attr('content');
}
}
item.pubDate = $('meta[name="PubDate"]').length ? timezone(parseDate($('meta[name="PubDate"]').attr('content') as string, 'YYYY-MM-DD HH:mm'), 8) : item.pubDate;
return item;
})
)
);
await browser.close();
return {
allowEmpty: true,
title: '杭州市人民政府-政务服务公开',
link,
item: items,
};
}