我在台式windows10上运行的一点问题没有的程序拷贝到同样操作系统的笔记本上运行就会报异常
GPU process launch failed: error_code=18
[12336:6452:0308/172411.770:ERROR:gpu_process_host.cc(946)] GPU process launch failed: error_code=18
[12336:6452:0308/172413.534:ERROR:gpu_process_host.cc(946)] GPU process launch failed: error_code=18
[12336:6452:0308/172415.214:ERROR:gpu_process_host.cc(946)] GPU process launch failed: error_code=18
[12336:6452:0308/172416.402:ERROR:gpu_process_host.cc(946)] GPU process launch failed: error_code=18
[12336:6452:0308/172417.838:ERROR:gpu_process_host.cc(946)] GPU process launch failed: error_code=18
[12336:6452:0308/172417.838:FATAL:gpu_data_manager_impl_private.cc(440)] GPU process isn't usable. Goodbye.
刚开始一直是怀疑是没有添加禁用gpu加速参数导致,后来加上去--disable-gpu后还是报该异常。
最后将所有常用参数一个个尝试,添加--no-sandbox参数后解决。文章来源:https://www.toymoban.com/news/detail-506716.html
示例:文章来源地址https://www.toymoban.com/news/detail-506716.html
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
# 启动Chromedriver
service = Service('/path/to/chromedriver')
service.start()
# 初始化Chromedriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=service, options=options)
# 打开Google网站
driver.get('https://www.google.com/')
# 查找搜索框并输入搜索查询
search_box = driver.find_element(By.NAME, 'q')
search_box.send_keys('Selenium 4')
# 模拟按下回车键
ActionChains(driver).send_keys(Keys.ENTER).perform()
# 等待搜索结果出现并打印出来
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@class="g"]')))
search_results = driver.find_elements(By.XPATH, '//div[@class="g"]')
for result in search_results:
print(result.text)
# 关闭浏览器
driver.quit()
到了这里,关于解决selenium4在部分电脑上运行时报异常GPU process launch failed: error_code=18无法打开浏览器窗口的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!