硒和谷歌浏览器驱动程序不会在linux python上运行

当我把我的代码放在理论上看起来应该工作时,我无法让铬运行,我甚至遵循了教程,但我不断得到同样的错误消息。这是我放的代码:


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.)

它根本没有打开铬


波斯汪
浏览 123回答 2
2回答

慕妹3242003

您是否尝试过使铬驱动程序可执行?sudo chmod a+x chromedriver

牧羊人nacy

你试过吗: options.add_argument(“--远程调试端口=9222”)从此错误报告:https://github.com/SeleniumHQ/selenium/issues/6049解决方法是指定远程调试端口作为ChromeOptions的参数,例如:options.add_argument(“-远程调试端口= 9222”),如果您在容器中运行,请将驱动程序设置为无外设,如sops.headless = True,否则使用类似pyvirtualdisplay之类的东西作为屏幕截图。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python