debug_after_click_v3.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """After click: dump screenshot + all new elements + all network requests.
  2. We need to know:
  3. 1. Did 996box actually call geetest (network log)?
  4. 2. If yes, what CSS class wraps the widget?
  5. 3. Are there any 996box-custom captcha-related elements?
  6. """
  7. import asyncio
  8. import sys
  9. from pathlib import Path
  10. _HERE = Path(__file__).resolve().parent
  11. sys.path.insert(0, str(_HERE.parent / "src"))
  12. from playwright.async_api import async_playwright
  13. EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  14. URL = "https://pc.hzwlan.com/login/account"
  15. async def main():
  16. out = _HERE / "jfbym_diag"
  17. requests_log = []
  18. async with async_playwright() as p:
  19. browser = await p.chromium.launch(executable_path=EDGE, headless=True)
  20. ctx = await browser.new_context(viewport={"width": 1366, "height": 768})
  21. page = await ctx.new_page()
  22. page.on("request", lambda r: requests_log.append(
  23. f"-> {r.method} {r.url[:100]}"
  24. ))
  25. page.on("response", lambda r: requests_log.append(
  26. f"<- {r.status} {r.url[:100]}"
  27. ))
  28. await page.goto(URL, wait_until="networkidle", timeout=30000)
  29. await page.evaluate(
  30. "([u, p]) => {"
  31. " const setVal = (sel, v) => {"
  32. " const el = document.querySelector(sel);"
  33. " Object.getOwnPropertyDescriptor("
  34. " window.HTMLInputElement.prototype, 'value').set.call(el, v);"
  35. " el.dispatchEvent(new Event('input', {bubbles: true}));"
  36. " };"
  37. " setVal('input#username', u);"
  38. " setVal('input#password', p);"
  39. " const btn = document.querySelector("
  40. " 'button.login-form_box__submit_button');"
  41. " if (btn) { btn.disabled = false; btn.classList.remove('disabled'); }"
  42. "}",
  43. ["longwu988", "Longwu1988"],
  44. )
  45. await page.wait_for_timeout(300)
  46. await page.locator("button.login-form_box__submit_button").first.click(force=True)
  47. # Wait long enough for any captcha widget to appear
  48. await page.wait_for_timeout(8000)
  49. await page.screenshot(path=str(out / "a1_after_click_v3.png"), full_page=True)
  50. info = await page.evaluate("""() => ({
  51. url: location.href,
  52. any_geetest_class: !!document.querySelector('[class*=geetest]'),
  53. any_geetest_id: !!document.querySelector('[id*=geetest]'),
  54. any_geetest_iframe:!!document.querySelector('iframe[src*=geetest]'),
  55. any_canvas: document.querySelectorAll('canvas').length,
  56. captcha_els: [...document.querySelectorAll('[class*=captcha]')]
  57. .slice(0,15).map(e => ({tag:e.tagName, cls:e.className.slice(0,80)})),
  58. all_iframes: [...document.querySelectorAll('iframe')].map(i => i.src.slice(0,90)),
  59. body_text_snippet: document.body.innerText.slice(0, 500),
  60. })""")
  61. print(f"url: {info['url']}")
  62. print(f"any_geetest_class: {info['any_geetest_class']}")
  63. print(f"any_geetest_id: {info['any_geetest_id']}")
  64. print(f"any_geetest_iframe: {info['any_geetest_iframe']}")
  65. print(f"any_canvas: {info['any_canvas']}")
  66. print(f"captcha_els: {info['captcha_els']}")
  67. print(f"iframes: {info['all_iframes']}")
  68. print(f"body text snippet: {info['body_text_snippet']!r}")
  69. await browser.close()
  70. print(f"\nscreenshot: {out / 'a1_after_click_v3.png'}")
  71. print(f"\n--- network activity (last 20) ---")
  72. for r in requests_log[-20:]:
  73. print(f" {r}")
  74. asyncio.run(main())