F: Improve features
This commit is contained in:
parent
721358aee8
commit
4927837ac6
|
@ -5,8 +5,8 @@ import { USER_DATA_DIR } from './setup';
|
||||||
const IN_LOGIN = 'iborisov@acconcept.ru';
|
const IN_LOGIN = 'iborisov@acconcept.ru';
|
||||||
const IN_PASSWORD = 'PuNS8br2';
|
const IN_PASSWORD = 'PuNS8br2';
|
||||||
|
|
||||||
// const IN_LOGIN = "dm9175025694";
|
// const IN_LOGIN = 'dm9175025694';
|
||||||
// const IN_PASSWORD = "52547";
|
// const IN_PASSWORD = '52547';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Launch persistent context with visible browser
|
// Launch persistent context with visible browser
|
||||||
|
@ -14,7 +14,8 @@ const IN_PASSWORD = 'PuNS8br2';
|
||||||
headless: false
|
headless: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const page = await context.newPage();
|
try {
|
||||||
|
const page = context.pages().length > 0 ? context.pages()[0] : await context.newPage();
|
||||||
|
|
||||||
await page.goto('https://account.garant.ru/login');
|
await page.goto('https://account.garant.ru/login');
|
||||||
|
|
||||||
|
@ -29,8 +30,9 @@ const IN_PASSWORD = 'PuNS8br2';
|
||||||
})
|
})
|
||||||
.waitFor();
|
.waitFor();
|
||||||
|
|
||||||
// Save storage state to file
|
|
||||||
await fs.writeFile('auth.json', JSON.stringify(await page.context().storageState()));
|
await fs.writeFile('auth.json', JSON.stringify(await page.context().storageState()));
|
||||||
|
|
||||||
console.log('✅ Saved login state to auth.json');
|
console.log('✅ Saved login state to auth.json');
|
||||||
|
} finally {
|
||||||
|
await context.close();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -5,12 +5,12 @@ import { test } from './setup';
|
||||||
import { executeSearch } from './search';
|
import { executeSearch } from './search';
|
||||||
|
|
||||||
/** Input text prompt */
|
/** Input text prompt */
|
||||||
const IN_TEXT_PROMPT = 'Министерство труда, занятости и социальной защиты Республики Коми';
|
const IN_TEXT_PROMPT = 'Представительство Республики Коми в Северо-Западном регионе Российской Федерации';
|
||||||
const IN_TITLE_PROMPT = '';
|
const IN_TITLE_PROMPT = '';
|
||||||
|
|
||||||
/** Output file naming */
|
/** Output file naming */
|
||||||
const OUT_NAME = 'output';
|
const OUT_NAME = 'output';
|
||||||
const OUT_SUFFIX = '_1';
|
const OUT_SUFFIX = '_22';
|
||||||
const OUT_FILENAME = `output/${OUT_NAME}${OUT_SUFFIX}.csv`;
|
const OUT_FILENAME = `output/${OUT_NAME}${OUT_SUFFIX}.csv`;
|
||||||
|
|
||||||
interface DocumentInfo {
|
interface DocumentInfo {
|
||||||
|
@ -31,6 +31,7 @@ test('scrape documents list', async ({ page }) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const documents = await readData(page);
|
const documents = await readData(page);
|
||||||
|
|
||||||
if (documents.length === 0) {
|
if (documents.length === 0) {
|
||||||
console.log('No data found');
|
console.log('No data found');
|
||||||
return;
|
return;
|
||||||
|
@ -55,11 +56,19 @@ async function readData(page: Page): Promise<DocumentInfo[]> {
|
||||||
const cleanText = nameEl ? (nameEl.cloneNode(true) as HTMLElement) : null;
|
const cleanText = nameEl ? (nameEl.cloneNode(true) as HTMLElement) : null;
|
||||||
|
|
||||||
if (cleanText) {
|
if (cleanText) {
|
||||||
cleanText.querySelectorAll('em').forEach(em => em.remove());
|
cleanText.querySelectorAll('em').forEach(em => {
|
||||||
|
const parent = em.parentNode;
|
||||||
|
if (parent) {
|
||||||
|
while (em.firstChild) {
|
||||||
|
parent.insertBefore(em.firstChild, em);
|
||||||
|
}
|
||||||
|
parent.removeChild(em);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = cleanText?.textContent?.trim() ?? '';
|
const name = cleanText?.textContent?.trim() ?? '';
|
||||||
return { name: name, href: href };
|
return { name: name, href: 'https://internet.garant.ru' + href };
|
||||||
})
|
})
|
||||||
.filter(item => !!item.href && !!item.name)
|
.filter(item => !!item.href && !!item.name)
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,7 +4,6 @@ const GLOBAL_FILTERS = [
|
||||||
'Федеральные министерства и ведомства',
|
'Федеральные министерства и ведомства',
|
||||||
'Правительство России и СССР',
|
'Правительство России и СССР',
|
||||||
'Президент России и СССР',
|
'Президент России и СССР',
|
||||||
'Органы судебной власти РФ и СССР',
|
|
||||||
'Органы законодательной власти России и СССР'
|
'Органы законодательной власти России и СССР'
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
@ -88,8 +87,8 @@ export async function executeSearch(page: Page, options: SearchOptions) {
|
||||||
await listItem.locator('img').nth(1).click();
|
await listItem.locator('img').nth(1).click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Выбрать', exact: true }).click();
|
await page.getByRole('button', { name: 'Выбрать', exact: true }).click();
|
||||||
|
|
||||||
await page.getByRole('button', { name: 'Найти (Enter)' }).click();
|
await page.getByRole('button', { name: 'Найти (Enter)' }).click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user