| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- """Properly read the 50001 error and trace the real flow.
- Three things to do:
- 1. Force UTF-8 output so we can read the actual error message
- 2. Wait for geetest to fully load (with screenshot to confirm)
- 3. After solving, capture the captcha and send it WITH the form
- """
- import asyncio
- import base64
- import json
- import os
- import sys
- from pathlib import Path
- # Force UTF-8 console output
- sys.stdout.reconfigure(encoding="utf-8", errors="replace")
- sys.stderr.reconfigure(encoding="utf-8", errors="replace")
- _HERE = Path(__file__).resolve().parent
- sys.path.insert(0, str(_HERE.parent / "src"))
- from cq2_sdk.env_loader import load_env
- load_env(_HERE.parent / ".env")
- from cq2_sdk.login.jfbym import JfbymSliderSolver
- from cq2_sdk.login.box_996 import Box996Login
- from cq2_sdk.store import UserStore, connection
- EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
- URL = "https://pc.hzwlan.com/login/account"
- async def main():
- from playwright.async_api import async_playwright
- async with async_playwright() as p:
- browser = await p.chromium.launch(executable_path=EDGE, headless=True)
- ctx = await browser.new_context(viewport={"width": 1366, "height": 768})
- page = await ctx.new_page()
- # 1. Open page, fill form via React-friendly native setter
- await page.goto(URL, wait_until="networkidle", timeout=30000)
- await page.evaluate(
- "([u, p]) => {"
- " const setVal = (sel, v) => {"
- " const el = document.querySelector(sel);"
- " Object.getOwnPropertyDescriptor("
- " window.HTMLInputElement.prototype, 'value').set.call(el, v);"
- " el.dispatchEvent(new Event('input', {bubbles: true}));"
- " };"
- " setVal('input#username', u);"
- " setVal('input#password', p);"
- "}",
- ["longwu988", "Longwu1988"],
- )
- # 2. Wait for geetest widget to fully load
- print("[step 2] waiting for geetest widget...")
- try:
- await page.wait_for_selector(
- ".geetest_widget, .geetest_captcha, [class*=geetest]",
- timeout=10000,
- )
- print(" -> geetest widget present")
- except Exception as e:
- print(f" -> no geetest widget after 10s: {e}")
- print(f" -> page text: {(await page.locator('body').inner_text())[:200]}")
- # 3. Screenshot pre-submit state
- out = _HERE / "jfbym_diag"
- await page.screenshot(path=str(out / "a1_pre_submit.png"), full_page=True)
- print(f" -> screenshot: {out / 'a1_pre_submit.png'}")
- # 4. Detect captcha widget type and structure
- info = await page.evaluate("""() => {
- return {
- geetest_els: [...document.querySelectorAll('[class*=geetest]')].map(e => ({
- tag: e.tagName, cls: e.className.slice(0, 60)
- })),
- canvas_count: document.querySelectorAll('canvas').length,
- canvas_classes: [...document.querySelectorAll('canvas')].map(c => c.className),
- yidun_els: [...document.querySelectorAll('[class*=yidun],[class*=netease]')].map(e => ({
- tag: e.tagName, cls: e.className.slice(0, 60)
- })),
- iframe_count: document.querySelectorAll('iframe').length,
- iframe_srcs: [...document.querySelectorAll('iframe')].map(i => i.src.slice(0, 100)),
- };
- }""")
- print(f" -> geetest els: {info['geetest_els']}")
- print(f" -> canvases: {info['canvas_count']} {info['canvas_classes']}")
- print(f" -> yidun els: {info['yidun_els']}")
- print(f" -> iframes ({info['iframe_count']}): {info['iframe_srcs']}")
- # 5. Click submit, capture the response
- print("\n[step 5] clicking submit, capturing byPwd response...")
- async with page.expect_response("**/auth/v3/login/safe/byPwd") as resp_info:
- await page.locator("button.login-form_box__submit_button").first.click(force=True)
- response = await resp_info.value
- status = response.status
- body = await response.text()
- await browser.close()
- print(f"\n=== byPwd response ===")
- print(f"status: {status}")
- print(f"body: {body}")
- try:
- data = json.loads(body)
- print(f"parsed: code={data.get('code')}, msg={data.get('msg')!r}, data={data.get('data')}")
- except Exception:
- pass
- asyncio.run(main())
|