Selenium无法识别Chrome二进制文件,Chrome已崩溃
我正在尝试用chrome运行Selenium 我测试了这个问题: 但它会产生错误:找不到Chrome二进制文件 我测试了这个问题: 但它产生了一个错误:Chrome崩溃了 机器: Ubuntu 16和Python 3.4Selenium无法识别Chrome二进制文件,Chrome已崩溃,selenium,google-chrome,selenium-webdriver,selenium-chromedriver,Selenium,Google Chrome,Selenium Webdriver,Selenium Chromedriver,我正在尝试用chrome运行Selenium 我测试了这个问题: 但它会产生错误:找不到Chrome二进制文件 我测试了这个问题: 但它产生了一个错误:Chrome崩溃了 机器: Ubuntu 16和Python 3.4 from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "/
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "/usr/local/bin/chromedriver"
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'/usr/local/bin/chromedriver')
driver.get('http://google.com/')
输出
Traceback (most recent call last):
File "testdrive.py", line 11, in <module>
driver = webdriver.Chrome(options=options, executable_path=r'/usr/local/bin/chromedriver')
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.4/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/local/bin/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
回溯(最近一次呼叫最后一次):
文件“testdrive.py”,第11行,在
driver=webdriver.Chrome(options=options,executable_path=r'/usr/local/bin/chromedriver')
文件“/usr/local/lib/python3.4/site packages/selenium/webdriver/chrome/webdriver.py”,第81行,在__
期望的_能力=期望的_能力)
文件“/usr/local/lib/python3.4/site packages/selenium/webdriver/remote/webdriver.py”,第157行,在__
启动会话(功能、浏览器配置文件)
文件“/usr/local/lib/python3.4/site packages/selenium/webdriver/remote/webdriver.py”,第252行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/usr/local/lib/python3.4/site packages/selenium/webdriver/remote/webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python3.4/site packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:异常退出。
(未知错误:DevToolsActivePort文件不存在)
(从chrome location/usr/local/bin/chromedriver启动的进程不再运行,因此chromedriver假设chrome已经崩溃。)
有人能帮我吗?自动下载并安装支持当前安装的chrome版本的chromedriver。此安装程序支持Linux、MacOS和Windows操作系统 安装
pip install chromedriver-autoinstaller
用法
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
只需在要使用的模块中键入importchromedriver\u autoinstaller
示例
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
您使用的chrome驱动程序和chrome浏览器的版本是什么?python版本Chrome:91.0.4472.19;Python版本:3.4Don`t working:sudo pip install chromedriver autoinstaller,输出:警告:目录'/home/ubuntu/.cache/pip/http'或其父目录不属于当前用户,缓存已被禁用。请检查该目录的权限和所有者。如果使用sudo执行pip,您可能需要sudo的-H标志如果我尝试运行,输出:Traceback import chromedriver\u autoinstaller,from。导入utils,logging.debug(f'Downloading chromedriver({chromedriver_version})…..)您没有相应的权限我相信我有权限是的,在消息的末尾它说:需求已经满足:chromedriver autoinstaller in/usr/local/lib/python3.4/site-packages(0.2.2)