错误信息:Passthrough is not supported, GL is swiftshader 解决方案:通过ChromeOptions() 配置Selenium启动参数进而实现chromedriver 在Windows环境中以“无头模式”运行时于控制台的输出信息的控制:
from selenium.webdriver import Chrome, ChromeOptions
SILENCE = True
def set_spider_option(chromedriver_path=None) -> Chrome:
chromedriver_path = "chromedriver" if chromedriver_path is None else chromedriver_path
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
|