ubuntu python playright headless true 获取错误页面

ubuntu python playright headless true get wrong page

ubuntu python playright headless true 获取错误页面,如何解决?

from playwright.sync_api import Playwright, sync_playwright
playwright = sync_playwright().start()
playwright.chromium.launch(headless=True, timeout=180 * 1000)
context = browser.new_context()
page = context.new_page()
page.goto('https://www.duda.co/login')
page.wait_for_load_state('networkidle')

page.fill('input[name=userName]', '')

获取错误页面,源代码

<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>


<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
</body></html>

if playwright headless=False in mac or window, return to normal page,但我用ubuntu,

您的目标站点可能不喜欢 Playwright 的默认用户代理,因此您必须提供自己的用户代理:

page = context.new_page(user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36")