import json, os, sys, time from playwright.sync_api import sync_playwright sys.stdout.reconfigure(encoding="utf-8", errors="replace") PORT=os.environ.get("CDP_PORT","9249"); OUT=r"C:\Users\User\tmp\chatco\card" tok=json.load(open(r"C:\Users\User\tmp\chatco\.tokens.json",encoding="utf-8")) ck=[] for raw in tok.get("cookies") or []: pr=raw.split(";")[0] if "=" in pr: n,v=pr.split("=",1); ck.append({"name":n.strip(),"value":v.strip(),"domain":".chat.co","path":"/"}) 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(ck) pg=ctx.pages[0] if ctx.pages else ctx.new_page(); pg.set_viewport_size({"width":1500,"height":1800}) pg.goto("https://chat.co/dashboard?view=classic", wait_until="domcontentloaded", timeout=90000); time.sleep(6) for lab in ["Accept","Skip"]: try: pg.click("text=%s"%lab, timeout=2500) except Exception: pass pg.click("text=node", timeout=6000); time.sleep(6) try: pg.click("text=Tune Bot", timeout=6000); time.sleep(6); print("tune bot opened", flush=True) except Exception as e: print("tune fail", str(e)[:60], flush=True) pg.screenshot(path=os.path.join(OUT,"tune.png")) body=pg.inner_text("body"); open(os.path.join(OUT,"tune.txt"),"w",encoding="utf-8").write(body) # все селекты/дропдауны на странице print("SELECTS:", pg.eval_on_selector_all("select","els=>els.map(e=>e.name||e.id||e.className.slice(0,20))"), flush=True) print("LABELS:", [x for x in body.split('\n') if 'model' in x.lower() or 'AI' == x.strip()][:10], flush=True) for sel in ["text=DeepSeek-R1", "button:has-text('DeepSeek')", "[role=combobox]"]: try: pg.click(sel, timeout=4000); time.sleep(3) pg.screenshot(path=os.path.join(OUT,"tune_drop.png")) t=pg.inner_text("body"); open(os.path.join(OUT,"tune_drop.txt"),"w",encoding="utf-8").write(t) print("opened", sel, "| sample:", " ".join(t[:300].split())[:200], flush=True) break except Exception: continue