F: Improve features

This commit is contained in:
Ivan 2025-05-23 20:37:41 +03:00
parent 721358aee8
commit 4927837ac6
3 changed files with 33 additions and 23 deletions

View File

@ -5,8 +5,8 @@ import { USER_DATA_DIR } from './setup';
const IN_LOGIN = 'iborisov@acconcept.ru';
const IN_PASSWORD = 'PuNS8br2';
// const IN_LOGIN = "dm9175025694";
// const IN_PASSWORD = "52547";
// const IN_LOGIN = 'dm9175025694';
// const IN_PASSWORD = '52547';
(async () => {
// Launch persistent context with visible browser
@ -14,23 +14,25 @@ const IN_PASSWORD = 'PuNS8br2';
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');
await page.getByRole('textbox').fill(IN_LOGIN);
await page.getByRole('button', { name: 'Войти' }).click();
await page.getByRole('textbox').fill(IN_PASSWORD);
await page.getByRole('button', { name: 'Войти' }).click();
await page.getByRole('textbox').fill(IN_LOGIN);
await page.getByRole('button', { name: 'Войти' }).click();
await page.getByRole('textbox').fill(IN_PASSWORD);
await page.getByRole('button', { name: 'Войти' }).click();
await page
.getByRole('button', {
name: 'Выйти из текущего сеанса и сменить пользователя'
})
.waitFor();
await page
.getByRole('button', {
name: 'Выйти из текущего сеанса и сменить пользователя'
})
.waitFor();
// Save storage state to file
await fs.writeFile('auth.json', JSON.stringify(await page.context().storageState()));
console.log('✅ Saved login state to auth.json');
await fs.writeFile('auth.json', JSON.stringify(await page.context().storageState()));
console.log('✅ Saved login state to auth.json');
} finally {
await context.close();
}
})();

View File

@ -5,12 +5,12 @@ import { test } from './setup';
import { executeSearch } from './search';
/** Input text prompt */
const IN_TEXT_PROMPT = 'Министерство труда, занятости и социальной защиты Республики Коми';
const IN_TEXT_PROMPT = 'Представительство Республики Коми в Северо-Западном регионе Российской Федерации';
const IN_TITLE_PROMPT = '';
/** Output file naming */
const OUT_NAME = 'output';
const OUT_SUFFIX = '_1';
const OUT_SUFFIX = '_22';
const OUT_FILENAME = `output/${OUT_NAME}${OUT_SUFFIX}.csv`;
interface DocumentInfo {
@ -31,6 +31,7 @@ test('scrape documents list', async ({ page }) => {
});
const documents = await readData(page);
if (documents.length === 0) {
console.log('No data found');
return;
@ -55,11 +56,19 @@ async function readData(page: Page): Promise<DocumentInfo[]> {
const cleanText = nameEl ? (nameEl.cloneNode(true) as HTMLElement) : null;
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() ?? '';
return { name: name, href: href };
return { name: name, href: 'https://internet.garant.ru' + href };
})
.filter(item => !!item.href && !!item.name)
);

View File

@ -4,7 +4,6 @@ const GLOBAL_FILTERS = [
'Федеральные министерства и ведомства',
'Правительство России и СССР',
'Президент России и СССР',
'Органы судебной власти РФ и СССР',
'Органы законодательной власти России и СССР'
] as const;
@ -88,8 +87,8 @@ export async function executeSearch(page: Page, options: SearchOptions) {
await listItem.locator('img').nth(1).click();
}
}
await page.getByRole('button', { name: 'Выбрать', exact: true }).click();
await page.getByRole('button', { name: 'Найти (Enter)' }).click();
}