from playwright.sync_api import sync_playwright import time, os def run(): with sync_playwright() as p: browser = p.chromium.connect_over_cdp('http://127.0.0.1:9222') context = browser.contexts[0] page = context.pages[0] print(f'Start Harvest. Current URL: {page.url}') # 1. Screenshot of the list page.screenshot(path='/app/appeals_list_final.png', full_page=True) print('List screenshot saved.') # 2. Click first appeal link # The number is 73-2026-5028 first_appeal = page.get_by_text('73-2026-5028').first if first_appeal.is_visible(): print('Entering appeal 73-2026-5028...') first_appeal.click() page.wait_for_load_state('networkidle') time.sleep(5) # 3. Screenshot inside page.screenshot(path='/app/appeal_inside.png', full_page=True) print('Inside screenshot saved.') # 4. Try to download ALL try: download_btn = page.get_by_text('Скачать все').first if download_btn.is_visible(): print('Clicking Download All...') with page.expect_download(timeout=60000) as download_info: download_btn.click() download = download_info.value path = f'/app/downloads/73-2026-5028_archive.zip' download.save_as(path) print(f'Archive saved to {path}') else: print('Download All button NOT found.') except Exception as e: print(f'Download failed: {e}') else: print('Appeal 73-2026-5028 NOT found in list.') browser.close() if __name__ == '__main__': if not os.path.exists('/app/downloads'): os.makedirs('/app/downloads') run()