domovoy_bot/scraper_gis/live_control.py

38 lines
1.7 KiB
Python
Raw Permalink 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:
# Подключаемся к уже открытому на экране браузеру
browser = p.chromium.connect_over_cdp('http://localhost:9222')
context = browser.contexts[0]
page = context.pages[0]
print(f'Подключился к браузеру. URL: {page.url}')
# 1. Переходим в Обращения (если мы не там)
if 'appeals' not in page.url:
print('Перехожу в раздел Обращений...')
page.goto('https://my.dom.gosuslugi.ru/citizen-cabinet/#!/appeals/applicant/search')
page.wait_for_load_state('networkidle')
time.sleep(5)
# 2. Подсвечиваем элементы, чтобы пользователь видел активность
# Мы будем рисовать рамки вокруг номеров обращений
print('Ищу номера обращений...')
page.evaluate('''() => {
const links = Array.from(document.querySelectorAll('a'));
links.filter(a => a.href.includes('appeals/view/')).forEach(a => {
a.style.border = '3px solid red';
a.style.backgroundColor = 'yellow';
});
}''')
page.screenshot(path='/app/live_discovery.png')
print('Сделал скриншот с подсветкой.')
# Не закрываем браузер! Просто отключаемся
browser.close()
if __name__ == '__main__':
run()