python Selenium --headless 参数触发网站的安全功能

python Selenium --headless argument triggers safety feature of the webside

我正在做一个小项目,我正在那里登录 quizlet。问题是,当我 运行 我的程序没有任何 chrome 驱动程序选项时,没有问题,它工作得很好。但是在我添加参数的地方,quizlet 不允许我登录。
这些是我的论点:

CHROME_PATH = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
CHROMEDRIVER_PATH = r"C:\Program Files (x86)\Python38-32\chromedriver.exe"
WINDOW_SIZE = "3840,2160"
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.binary_location = CHROME_PATH

driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, options=chrome_options)

如你所见,我得到了一个错误:
here is a picture of error

当我编辑这一行时:
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH)
它工作得很好,但我不想看到 window。
我看起来像“--headless”参数触发了网站的安全功能。
这太奇怪了。有什么建议吗?

我认为这是 Chromedriver 的一个错误,请参阅下面的 link 以获得 Selenium 团队的解释。

https://github.com/SeleniumHQ/selenium/issues/8967

我会监控 Chromedriver 错误跟踪器以获取有关 Headless 模式错误的任何更新,请参阅下面的 link: https://bugs.chromium.org/p/chromedriver/issues/list

抱歉没有帮助...

options = webdriver.ChromeOptions()
#options.headless = True
options.add_argument("--window-size=1920,1080")
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument(
    "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
browser = webdriver.Chrome(options=options)

尝试使用用户代理,因为 headless 使用的用户代理与普通用户代理不同