domovoy_bot/scraper_gis/capture_list.py

35 lines
1.3 KiB
Python

from playwright.sync_api import sync_playwright
import json, 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(f'Attached to: {page.url}')
# Ждем прогрузки таблицы
page.wait_for_selector('tr', timeout=30000)
time.sleep(5)
data = []
rows = page.query_selector_all('tr')
for row in rows:
text = row.inner_text()
if '73-20' in text:
link = row.query_selector('a[href*="appeals/view/"]')
if link:
number = link.inner_text().strip()
href = link.get_attribute('href')
data.append({'number': number, 'href': href})
with open('/app/appeals_queue.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f'SUCCESS: Captured {len(data)} items.')
browser.close()
except Exception as e:
print(f'ERROR: {e}')
if __name__ == '__main__':
run()