首页 > 解决方案 > selenium.common.exceptions.webdriverexception:消息:“chromedriver.exe”意外退出。状态代码为:1

问题描述

我是 Python 的新手,我正在尝试使用 selenium webdriver 从网页进行网页抓取。当我运行我的代码时,我在获得我需要的结果方面没有问题,但是当其他人尝试从可执行文件运行代码时,它会显示错误:selenium.common.exceptions.webdriverexception: message: 'chromedriver.exe' exited.status 代码是: 1. 我保存 chromedriver.exe 的路径是公共存储库。有人可以帮我吗?这是我正在使用的一段代码:

from selenium import webdriver

url= "https://www.byma.com.ar/obligaciones-negociables/"
    
driver = webdriver.Chrome(executable_path=r'\\path\\chromedriver.exe')

driver.implicitly_wait(30)
    
driver.get(url)
    
time.sleep(2)

标签: seleniumwebdriver

解决方案


您不需要driver像这样设置:

driver = webdriver.Chrome(executable_path=r'\\path\\chromedriver.exe')

做这个 :

这是一个先决条件

安装

pip install chromedriver-autoinstaller

用法:

Just type import chromedriver_autoinstaller in the module you want to use chromedriver.

例子

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

并将此更改导出到您的可执行文件


推荐阅读