selenium.common.exceptions.webdriverexception:消息:“chromedriver.exe”意外退出。状态代码为:1

时间:2021-06-18 14:30:20

标签: selenium webdriver

我是 Python 新手,我正在尝试使用 selenium webdriver 从网页进行网络抓取。当我运行我的代码时,我在获得我需要的结果方面没有问题,但是当其他人尝试从可执行文件运行代码时,它会显示错误:selenium.common.exceptions.webdriverexception:消息:'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)

1 个答案:

答案 0 :(得分:0)

您不需要像这样设置 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

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