57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
from playwright.sync_api import sync_playwright
|
|
import time
|
|
|
|
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]
|
|
|
|
print('Clicking Search button...')
|
|
page.locator('button:has-text("Найти")').click()
|
|
|
|
print('Waiting for list...')
|
|
page.wait_for_selector('tr', timeout=30000)
|
|
time.sleep(5)
|
|
|
|
# Screenshot the revealed list
|
|
page.screenshot(path='/app/revealed_list.png', full_page=True)
|
|
print('List revealed and screenshotted.')
|
|
|
|
# Collect data
|
|
data = []
|
|
rows = page.query_selector_all('tr')
|
|
for row in rows:
|
|
if '73-20' in row.inner_text():
|
|
link = row.query_selector('a[href*="appeals/view/"]')
|
|
if link:
|
|
data.append({'num': link.inner_text().strip(), 'href': link.get_attribute('href')})
|
|
|
|
if data:
|
|
print(f'Entering first appeal: {data[0]["num"]}')
|
|
page.locator('a:has-text("' + data[0]['num'] + '")').first.click()
|
|
page.wait_for_load_state('networkidle')
|
|
time.sleep(10)
|
|
page.screenshot(path='/app/appeal_inner_view.png', full_page=True)
|
|
|
|
# Download All
|
|
try:
|
|
btn = page.locator('button:has-text("Скачать все")').first
|
|
if btn.is_visible():
|
|
print('Clicking Download All...')
|
|
with page.expect_download(timeout=120000) as download_info:
|
|
btn.click()
|
|
download = download_info.value
|
|
download.save_as('/app/downloads/harvested.zip')
|
|
print('SUCCESS: Downloaded harvested.zip')
|
|
else:
|
|
print('Button "Скачать все" NOT found inside.')
|
|
except Exception as e:
|
|
print(f'Download failed: {e}')
|
|
|
|
browser.close()
|
|
except Exception as e:
|
|
print(f'Error: {e}')
|
|
|
|
if __name__ == '__main__':
|
|
run()
|