update
This commit is contained in:
@@ -144,27 +144,37 @@ async function scrapeMembers(frame: Frame): Promise<FdiskMember[]> {
|
|||||||
// We clear it before submitting so all members of the fire station are returned.
|
// We clear it before submitting so all members of the fire station are returned.
|
||||||
const hasForm = await frame.$('form[name="frmsearch"]') !== null;
|
const hasForm = await frame.$('form[name="frmsearch"]') !== null;
|
||||||
if (hasForm) {
|
if (hasForm) {
|
||||||
const cleared = await frame.evaluate(() => {
|
const fieldDump = await frame.evaluate(() => {
|
||||||
const form = (document as any).forms['frmsearch'];
|
const form = (document as any).forms['frmsearch'];
|
||||||
if (!form) return [];
|
if (!form) return { cleared: [], allFields: [] };
|
||||||
const clearedFields: string[] = [];
|
const cleared: string[] = [];
|
||||||
|
const allFields: string[] = [];
|
||||||
for (const el of Array.from(form.elements) as HTMLInputElement[]) {
|
for (const el of Array.from(form.elements) as HTMLInputElement[]) {
|
||||||
|
if (el.type === 'hidden') continue;
|
||||||
const name = (el.name ?? '').toLowerCase();
|
const name = (el.name ?? '').toLowerCase();
|
||||||
const id = (el.id ?? '').toLowerCase();
|
const id = (el.id ?? '').toLowerCase();
|
||||||
|
if (el.value) allFields.push(`${el.name || el.id}=${el.value}`);
|
||||||
if (name.includes('standesbuch') || id.includes('standesbuch')) {
|
if (name.includes('standesbuch') || id.includes('standesbuch')) {
|
||||||
el.value = '';
|
el.value = '';
|
||||||
clearedFields.push(el.name || el.id);
|
cleared.push(el.name || el.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return clearedFields;
|
return { cleared, allFields };
|
||||||
});
|
});
|
||||||
if (cleared.length > 0) {
|
if (fieldDump.allFields.length > 0) {
|
||||||
log(`Cleared Standesbuchnummer filter fields: ${cleared.join(', ')}`);
|
log(`Search form active filters before clear: ${fieldDump.allFields.join(', ')}`);
|
||||||
|
}
|
||||||
|
if (fieldDump.cleared.length > 0) {
|
||||||
|
log(`Cleared Standesbuchnummer filter fields: ${fieldDump.cleared.join(', ')}`);
|
||||||
} else {
|
} else {
|
||||||
log('Search form found — no Standesbuchnummer field detected, submitting as-is');
|
log('Search form found — no Standesbuchnummer field detected, submitting as-is');
|
||||||
}
|
}
|
||||||
await frame.evaluate(() => { (document as any).forms['frmsearch'].submit(); });
|
// Use Promise.all to start waiting for navigation BEFORE triggering the submit,
|
||||||
await frame.waitForLoadState('networkidle');
|
// otherwise waitForLoadState resolves against the already-idle current page.
|
||||||
|
await Promise.all([
|
||||||
|
frame.waitForNavigation({ waitUntil: 'networkidle', timeout: 30000 }),
|
||||||
|
frame.evaluate(() => { (document as any).forms['frmsearch'].submit(); }),
|
||||||
|
]);
|
||||||
log(`After form submit: ${frame.url()}`);
|
log(`After form submit: ${frame.url()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user