debug_login2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. Debug login - capture network requests.
  3. """
  4. from playwright.sync_api import sync_playwright
  5. BASE_URL = "http://localhost:80"
  6. with sync_playwright() as p:
  7. browser = p.chromium.launch(headless=True)
  8. page = browser.new_page(viewport={"width": 1440, "height": 900})
  9. responses = []
  10. def on_response(response):
  11. if "/auth/login" in response.url:
  12. responses.append({
  13. "url": response.url,
  14. "status": response.status,
  15. "body": response.text()[:500] if response.status != 200 else response.text()[:500],
  16. })
  17. page.on("response", on_response)
  18. page.goto(f"{BASE_URL}/login", wait_until="networkidle", timeout=30000)
  19. page.wait_for_timeout(1000)
  20. page.locator('input[placeholder="用户名"]').fill("admin")
  21. page.locator('input[placeholder="密码"]').fill("admin123")
  22. page.locator('button:has-text("登")').click()
  23. page.wait_for_timeout(5000)
  24. print(f"URL: {page.url}")
  25. for r in responses:
  26. print(f"\n Response: {r['url']}")
  27. print(f" Status: {r['status']}")
  28. print(f" Body: {r['body'][:300]}")
  29. browser.close()