domovoy_bot/scraper_gis/click_appeal.py

36 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]
# Находим ссылку по тексту номера
# Но в таблице текст - это тема. Используем текст темы.
target_text = 'ТРЕБОВАНИЕ о недопустимости предоставления недостоверных сведений'
print(f'Looking for link with text: {target_text}')
# Пытаемся кликнуть по первой ссылке в таблице
page.locator('tr a[href*="appeals/view/"]').first.click()
print('Clicked! Waiting for load...')
time.sleep(10)
print(f'New URL: {page.url}')
page.screenshot(path='/app/appeal_page_success.png', full_page=True)
# Пробуем найти кнопку Скачать все
btn = page.get_by_text('Скачать все')
if btn.is_visible():
print('Download button visible!')
btn.highlight()
page.screenshot(path='/app/download_btn_found.png')
browser.close()
except Exception as e:
print(f'ERROR: {e}')
if __name__ == '__main__':
run()