debug_after_click_v2.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """After login click, observe the page: screenshot + dump new DOM elements.
  2. We know now that:
  3. - click does trigger a state change (the form submit fires, or geetest starts loading)
  4. - but .geetest_canvas_bg selector times out (wrong class)
  5. - the original geetest v4 widget uses .geetest_canvas_bg, .geetest_canvas_slice, etc.
  6. - 996box may have renamed or wrapped them in a custom container
  7. So dump every iframe and every new element with class containing 'geetest' or 'captcha'.
  8. """
  9. import asyncio
  10. import sys
  11. from pathlib import Path
  12. _HERE = Path(__file__).resolve().parent
  13. sys.path.insert(0, str(_HERE.parent / "src"))
  14. from playwright.async_api import async_playwright
  15. EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  16. URL = "https://pc.hzwlan.com/login/account"
  17. async def main():
  18. out = _HERE / "jfbym_diag"
  19. async with async_playwright() as p:
  20. browser = await p.chromium.launch(executable_path=EDGE, headless=True)
  21. ctx = await browser.new_context(viewport={"width": 1366, "height": 768})
  22. page = await ctx.new_page()
  23. await page.goto(URL, wait_until="networkidle", timeout=30000)
  24. await page.fill("input#username", "longwu988")
  25. await page.locator("input#username").press("Tab")
  26. await page.fill("input#password", "Longwu1988")
  27. await page.locator("input#password").press("Tab")
  28. await page.wait_for_timeout(300)
  29. await page.locator("button.login-form_box__submit_button").first.click(force=True)
  30. # Wait longer for the widget to appear (geetest loads its own assets)
  31. await page.wait_for_timeout(8000)
  32. await page.screenshot(path=str(out / "a1_after_click_v2.png"), full_page=True)
  33. info = await page.evaluate("""() => ({
  34. url: location.href,
  35. title: document.title,
  36. any_geetest: !!document.querySelector('[class*=geetest]'),
  37. any_captcha: !!document.querySelector('[class*=captcha]'),
  38. geetest_els: [...document.querySelectorAll('[class*=geetest]')]
  39. .slice(0, 15)
  40. .map(e => ({tag: e.tagName, cls: e.className.slice(0, 80)})),
  41. captcha_els: [...document.querySelectorAll('[class*=captcha]')]
  42. .slice(0, 15)
  43. .map(e => ({tag: e.tagName, cls: e.className.slice(0, 80)})),
  44. iframes: [...document.querySelectorAll('iframe')].map(i => i.src.slice(0, 100)),
  45. canvas_count: document.querySelectorAll('canvas').length,
  46. canvas_classes: [...document.querySelectorAll('canvas')]
  47. .map(c => c.className.slice(0, 80)),
  48. })""")
  49. print(f"url: {info['url']}")
  50. print(f"any_geetest: {info['any_geetest']}, any_captcha: {info['any_captcha']}")
  51. print(f"geetest_els: {info['geetest_els']}")
  52. print(f"captcha_els: {info['captcha_els']}")
  53. print(f"canvases: {info['canvas_count']} {info['canvas_classes']}")
  54. print(f"iframes: {info['iframes']}")
  55. await browser.close()
  56. print(f"\nscreenshot: {out / 'a1_after_click_v2.png'}")
  57. asyncio.run(main())