【问题标题】:python Selenium --headless argument triggers safety feature of the webside [duplicate]python Selenium --headless 参数触发网页端的安全功能[重复]
【发布时间】:2021-05-18 17:31:12
【问题描述】:

我正在做一个小项目,并在那里登录到 quizlet。问题是,当我在没有任何 chrome 驱动程序选项的情况下运行我的程序时,它可以正常工作。但是在我添加参数的地方,测验不会让我登录。
这些是我的论点:

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)
它运行良好,但我不想看到窗口。
我看起来像“--headless”参数触发了网页端的安全功能。
这太奇怪了。有什么建议吗?

【问题讨论】:

    标签: python selenium selenium-webdriver webdriver


    【解决方案1】:
    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 使用与正常不同的用户代理

    【讨论】:

      【解决方案2】:

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

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

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

      抱歉没有帮助...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-07
        • 2021-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-23
        相关资源
        最近更新 更多