Featured image of post 『 Python 』Passthrough is not supported, GL is swiftshader

『 Python 』Passthrough is not supported, GL is swiftshader

错误信息

1
Passthrough is not supported, GL is swiftshader.

解决方案

通过 ChromeOptions() 配置 Selenium 启动参数进而实现 chromedriver 在 Windows 环境中以“无头模式”运行时于控制台的输出信息的控制:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from selenium.webdriver import Chrome, ChromeOptions

# True:chromedriver静默启动
SILENCE = True


def set_spider_option(chromedriver_path=None) -> Chrome:
    # 调整chromedriver的读取路径,若不指定则尝试从环境变量中查找
    chromedriver_path = "chromedriver" if chromedriver_path is None else chromedriver_path
    # 实例化Chrome可选参数
    options = ChromeOptions()
    # 静默启动 参数组策略
    if SILENCE is True:
        options.add_argument('--headless')
        options.add_argument('--disable-gpu')
        options.add_argument("--disable-software-rasterizer")
    # 其他推荐设置
    options.add_argument('--log-level=3')
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    options.add_experimental_option('excludeSwitches', ['enable-automation'])
    return Chrome(options=options, executable_path=chromedriver_path)


def this_is_a_business(chromedriver_path):
    api = set_spider_option(chromedriver_path)
    try:
        api.get("https://www.baidu.com")
        input()
    finally:
        api.quit()


if __name__ == '__main__':
    this_is_a_business(chromedriver_path=None)

参考资料

[1] [Solved] Python Selenium Chromedriver Error: (Passthrough is not supported, GL is disabled) | DebugAH

[2] python - Passthrough is not supported, GL is disabled - Stack Overflow

You will to enjoy grander sight / By climing to a greater height.