43 lines
2.1 KiB
Python
43 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Открывает дашборд chat.co с готовыми cookie, ищет раздел моделей и снимает скрин."""
|
|
import json, os, re, sys, time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PORT = os.environ.get("CDP_PORT", "9244")
|
|
OUT = os.environ.get("CC_OUT", r"C:\Users\User\tmp\chatco\card")
|
|
|
|
tok = json.load(open(r"C:\Users\User\tmp\chatco\.tokens.json", encoding="utf-8"))
|
|
cookies = []
|
|
for raw in tok.get("cookies") or []:
|
|
pair = raw.split(";")[0]
|
|
if "=" not in pair:
|
|
continue
|
|
name, value = pair.split("=", 1)
|
|
cookies.append({"name": name.strip(), "value": value.strip(), "domain": ".chat.co", "path": "/"})
|
|
print("cookies:", [c["name"] for c in cookies], flush=True)
|
|
|
|
with sync_playwright() as p:
|
|
b = p.chromium.connect_over_cdp("http://127.0.0.1:%s" % PORT)
|
|
ctx = b.contexts[0]
|
|
ctx.add_cookies(cookies)
|
|
pg = ctx.pages[0] if ctx.pages else ctx.new_page()
|
|
pg.set_viewport_size({"width": 1440, "height": 1800})
|
|
pg.goto("https://chat.co/", wait_until="domcontentloaded", timeout=90000)
|
|
time.sleep(6)
|
|
print("url:", pg.url, "| title:", pg.title(), flush=True)
|
|
print("landing body:", " ".join(pg.inner_text("body")[:200].split()), flush=True)
|
|
# куда ведёт дашборд
|
|
for path in ["/dashboard", "/chatbots", "/chatbot", "/app", "/workspace"]:
|
|
try:
|
|
pg.goto("https://chat.co" + path, wait_until="domcontentloaded", timeout=45000)
|
|
time.sleep(5)
|
|
body = " ".join(pg.inner_text("body")[:300].split())
|
|
if "404" in pg.title() or "not found" in body.lower():
|
|
print(path, "-> 404", flush=True)
|
|
continue
|
|
print(path, "->", pg.url, "|", body[:150], flush=True)
|
|
pg.screenshot(path=os.path.join(OUT, "dash_%s.png" % path.strip("/")))
|
|
except Exception as e:
|
|
print(path, "ERR", str(e)[:70], flush=True)
|
|
print("links:", pg.eval_on_selector_all("a", "els => els.map(e => e.getAttribute('href')).filter(Boolean).slice(0,50)"), flush=True) |