项目文件夹

文件
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

52 行
2.0 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
import { CliError } from '@jackwener/opencli/errors';
export async function navigateViaVueRouter(page, query) {
await page.goto('https://flk.npc.gov.cn/index.html');
await page.wait(4);
const routerAvailable = await page.evaluate(`
(async () => {
const app = document.querySelector('#app');
const router = app?.__vue_app__?.config?.globalProperties?.$router;
if (!router) return false;
await router.push({ path: '/search', query: ${JSON.stringify(query)} });
return true;
})()
`);
if (!routerAvailable) {
throw new CliError(
'FRAMEWORK_CHANGED',
'Could not access Vue Router on flk.npc.gov.cn — the site may have been restructured.',
'Please report this issue so the adapter can be updated.',
);
}
await page.wait(5);
}
export async function extractLawResults(page, limit) {
const data = await page.evaluate(`
(async () => {
const normalize = v => (v || '').replace(/\\s+/g, ' ').trim();
for (let i = 0; i < 40; i++) {
if (document.querySelectorAll('.result-item').length > 0) break;
await new Promise(r => setTimeout(r, 500));
}
const results = [];
for (const el of document.querySelectorAll('.result-item')) {
const title = normalize(el.querySelector('.title-content')?.textContent);
if (!title) continue;
const status = normalize(el.querySelector('[class*="status"]')?.textContent);
const publish_date = normalize(el.querySelector('.publish-time')?.textContent).replace(/^公布日期[:]\\s*/, '');
const type = normalize(el.querySelector('.type')?.textContent);
const department = normalize(el.querySelector('.department')?.textContent);
results.push({ rank: results.length + 1, title, status, publish_date, type, department });
if (results.length >= ${limit}) break;
}
return results;
})()
`);
return Array.isArray(data) ? data : [];
}