selenium - 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)
解决方案
您不需要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
并将此更改导出到您的可执行文件
推荐阅读
- c++ - Cpp程序没有输出
- spring-boot - Keycloak 保护 Spring Boot 应用程序:尝试配置公开可用的页面
- javascript - 将弹出文本添加到 Folium FastMarkerCluster 标记
- node.js - 如何在电子中获取屏幕上按钮的位置
- javascript - 如何选择 id 存储在变量中的元素的子元素?
- java - JSON 中的 LinkedHashMap 在 get() 上返回 null
- .net - .Net Core API 中的 Azure B2C
- php - 两个日期之间的时间
- c++ - 如何解除 std 智能指针的自定义删除功能?
- c# - 循环通过 Xamarin.Android 上的 NetworkInterfaces 时没有 GatewayAddresses