简体   繁体   English

Python selenium Webdriver Chrome 修复

[英]Python selenium Webdriver Chrome fix

The code:编码:

from selenium import  webdriver
driver = webdriver.Chrome('/home/derlinuxnutzer/PycharmProjects/pythonProject1/chromedriver')
driver.get('https://www.google.com/')

The error: Traceback (most recent call last): File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/hh.py", line 2, in driver = webdriver.Chrome('/home/derlinuxnutzer/PycharmProjects/pythonProject1/chromedriver') File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in init RemoteWebDriver.错误: Traceback(最近一次调用最后一次):文件“/home/derlinuxnutzer/PycharmProjects/pythonProject1/hh.py”,第 2 行,在 driver = webdriver.Chrome('/home/derlinuxnutzer/PycharmProjects/pythonProject1/chromedriver')文件“/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py”,第 76 行, init RemoteWebDriver。 init ( File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/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: crashed. (unknown error: DevToolsActivePort f init (文件“/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py”,第 157 行,在init self.start_session(capabilities,browser_profile)文件中“/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py”,第 252 行,在 start_session 响应 = self.execute(Command.NEW_SESSION,参数)文件“/home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py”,第321行,在执行self.error_handler.check_response(response)文件“/ home/derlinuxnutzer/PycharmProjects/pythonProject1/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py",第 242 行,在 check_response 中引发 exception_class(message, screen, stacktrace) selenium.common.exceptions .WebDriverException:消息:未知错误:Chrome 无法启动:崩溃。(未知错误:DevToolsActivePort f ile doesn't exist) (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) ile 不存在)(从 chrome 位置 /opt/google/chrome/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已崩溃。)

Process finished with exit code 1进程以退出代码 1 结束

It should be with extension chromedriver.exe它应该带有扩展chromedriver.exe

from selenium import webdriver 
driver = webdriver.Chrome('/home/derlinuxnutzer/PycharmProjects/pythonProject1/chromedriver.exe')
driver.get('https://www.google.com/')

Ensure that your path is correct by calling it from terminal using cd command通过使用cd命令从终端调用它来确保您的路径是正确的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM