from playwright.sync_api import sync_playwright import json, time, re def run(): with sync_playwright() as p: try: browser = p.chromium.connect_over_cdp('http://127.0.0.1:9222') page = browser.contexts[0].pages[0] page.goto('https://my.dom.gosuslugi.ru/citizen-cabinet/#!/appeals/applicant/search') page.wait_for_load_state('networkidle') time.sleep(10) # Нажимаем кнопку 'Свернуть/Развернуть поиск' если нужно # На скриншоте видно панель поиска. Попробуем нажать 'Очистить' если она есть. try: # Очистка всех инпутов page.evaluate('''() => { document.querySelectorAll('input').forEach(i => { i.value = ''; }); // Пытаемся найти кнопку сброса const reset = Array.from(document.querySelectorAll('button')).find(b => b.innerText.includes('Очистить')); if (reset) reset.click(); }''') time.sleep(5) except: pass # Нажимаем Найти page.locator('button:has-text("Найти")').click() time.sleep(10) full_queue = [] while True: page.evaluate('document.querySelectorAll(".p-dialog-mask, .modal-backdrop").forEach(el => el.remove())') rows = page.locator('tr').all() for row in rows: text = row.inner_text() if '73-20' in text: link = row.locator('a[href*="appeals/view/"]').first href = link.get_attribute('href') num_match = re.search(r'73-202\d-\d+', text) num = num_match.group(0) if num_match else f"case_{time.time()}" if href and num not in [x['number'] for x in full_queue]: full_queue.append({'number': num, 'href': href}) next_btn = page.locator('a:has-text("следующая"), .pagination-next a').first if next_btn.is_visible() and next_btn.is_enabled(): page.evaluate('el => el.click()', next_btn.element_handle()) time.sleep(10) else: break output_path = '/app/services/gis_harvester/data/full_queue.json' with open(output_path, 'w', encoding='utf-8') as f: json.dump(full_queue, f, ensure_ascii=False, indent=2) print(f'ПОЛНЫЙ СПИСОК: {len(full_queue)} целей.') browser.close() except Exception as e: print(f'ERROR: {e}') if __name__ == "__main__": run()