当我把代码放进去时,我无法让chrome运行,理论上它看起来应该可以工作——我甚至遵循了教程,但我一直收到同样的错误消息。这是我放的代码:
from selenium import webdriver
#chromedriver varible with exact location to where its saved
chromedriver = "/home/jackmiller/Downloads/chromedriver"
#varible of drive to run open up the chrome driver which is located
#on my machine as chromedriver varible chromedriver
driver = webdriver.Chrome(chromedriver)
#open this website
driver.get('https://youtube.com')
当我在终端中运行代码时,它返回的是:
Traceback (most recent call last):
File "automation.py", line 8, in <module>
driver = webdriver.Chrome(chromedriver)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-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.)
它根本没有打开铬
您尝试过吗:options.add_argument("--远程调试端口=9222"(
根据此错误报告:https://github.com/SeleniumHQ/selenium/issues/6049
一种解决方法是将远程调试端口指定为ChromeOptions的参数,例如:options.add_argument("--remote debugging port=9222"(,如果您在容器中运行,则将驱动程序设为无头,例如options.headless=True,否则使用pyvirtualdisplay等方法进行屏幕截图。
您是否尝试使chromedriverfile可执行?sudo chmod a+x chromedriver