interplane.Get Omega
Read in your language

aien-translate

aien-dev/aien-translate

Brought by drakestapleton

branch main Branches Tags History

aien-translate / demo / check.py

17 lines · 833 bytes Raw Blame History
1"""Load the demo page with the real translate.js and report what it shows."""
2import json, sys
3from playwright.sync_api import sync_playwright
4
5url = sys.argv[1]
6with sync_playwright() as p:
7 b = p.chromium.launch()
8 pg = b.new_page()
9 reqs = []
10 pg.on("request", lambda r: reqs.append(r.url) if r.url.endswith(".json") or ".json?" in r.url else None)
11 pg.on("console", lambda m: print("console:", m.text[:200]) if m.type in ("error", "warning") else None)
12 pg.goto(url)
13 pg.wait_for_function("document.querySelector('h1').innerText.indexOf('操作系统') >= 0", timeout=120000)
14 pg.wait_for_timeout(2000)
15 out = pg.evaluate("""() => [...document.querySelectorAll('h1,p,button')].map(e => e.innerText)""")
16 print(json.dumps({"page": out, "requests": reqs}, ensure_ascii=False, indent=1))
17 b.close()