如何使用 python 和 chromedriver 获取硒以使用无头模式工作

问题描述

我正在尝试让 selenium 在无头模式下运行 chrome,但我不断收到此错误

[0119/174012.114:INFO:CONSOLE(3)] "A preload for 'https://www.bing.com/rp/lmu8EBCaPRMKtay8LSArGyY3mv4.br.js' is found,but is not used because the request credentials mode does not match. Consider taking a look at crossorigin attribute.",source: https://www.bing.com/rb/5q/cj,nj/sCPt57pbiTV6DFHANCn0N1monu0.js?bu=DOIj8yLRBYIj5SOMI5Qj6SO4I6Ei7COMDQ (3)
[0119/174012.970:INFO:CONSOLE(73)] "BSSO Telemetry: {"result":"Error","error":"NoExtension","type":"ChromeSsoTelemetry","data":{},"traces":["browseRSSO Initialized","Creating ChromebrowserCore provider","Sending message for method CreateProviderAsync","Received message for method CreateProviderAsync","Error: ChromebrowserCore error NoExtension: Extension is not installed."]}",source: https://login.microsoftonline.com/common/oauth2/authorize?client_id=9ea1ad79-fdb6-4f9a-8bc3-2b70f96e34c7&response_type=id_token&nonce=156143de-ffcd-48a3-977e-49b1927ca0d0&redirect_uri=https%3a%2f%2fwww.bing.com%2forgid%2fidtoken%2fnosignin&scope=openid&response_mode=form_post&msafed=0&prompt=none&state=%7b%22ig%22%3a%228CBA4BB2161B42E2AE5CE54340B61CEE%22%7d (73)
[0119/174014.718:INFO:CONSOLE(0)] "The resource https://www.bing.com/rp/lmu8EBCaPRMKtay8LSArGyY3mv4.br.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.",source: https://www.bing.com/ (0)

抛出这个错误代码是:

def computer_searches():
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    driver = webdriver.Chrome(executable_path=path,options=options)
    driver.set_page_load_timeout(15)
    driver.get("https://www.bing.com")

我相当确定问题只是无头模式,因为如果我在没有无头模式选项的情况下运行它,那么它可以完美运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)