gpt4 book ai didi

python - WebDriver异常: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist)

转载 作者:太空宇宙 更新时间:2023-11-03 20:43:25 29 4
gpt4 key购买 nike

尽管版本正确且已安装 UI,但使用 Selenium 的 Python 脚本无法创建 Chrome 实例。

我已经在这里查看了类似的线程,但似乎都没有解决该问题。该代码在 Windows 上运行 - 一旦我尝试在 Linux 上执行它,它就不再运行。我的预期目标是让它以可视方式打开 Chrome,因此我并不是在寻找涉及虚拟显示的解决方案。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')

driver = webdriver.Chrome('/home/ethan/chromedriver', chrome_options=options)
driver.set_window_size(1024, 600)
driver.maximize_window()

我安装了 Google Chrome 75.0.3770.100我还有 ChromeDriver 75.0.3770.90

这是代码的完整回溯:

File "cm_update_01.py", line 114, in <module>
if __name__ == "__main__": main()
File "cm_update_01.py", line 24, in main
with open(fetch_file()) as f:
File "cm_update_01.py", line 75, in fetch_file
driver = webdriver.Chrome('/home/ethan/chromedriver', chrome_options=options)
File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

最佳答案

这是针对java的,但我认为它应该适合你: https://github.com/SeleniumHQ/selenium/issues/4961#issuecomment-346821657
它说这是一个许可问题。尝试以 root 身份运行您的程序。

关于python - WebDriver异常: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56740289/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com