【问题标题】:selenium.common.exceptions.webdriverexception: message: 'chromedriver.exe' unexpectedly exited.status code was: 1selenium.common.exceptions.webdriverexception:消息:“chromedriver.exe”意外退出。状态代码为:1
【发布时间】:2021-09-03 07:11:38
【问题描述】:

我是 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)

【问题讨论】:

    标签: selenium webdriver


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答。这里的问题,我忘了提到,可执行文件的用户无法将可执行文件下载到他们的电脑上。那么,有没有办法将 de chromedriver.exe 包含在使用 pyinstaller 将项目运行到 .exe 时创建的“dist”文件夹的文件夹中?
    • 上述解决方案根本不需要chromedriver.exe
    • 好的,我想我已经明白你的意思了。感谢您的帮助!
    • 有帮助吗?如果是,如果它帮助您或解决了上述查询,请不要忘记将其标记为已接受的答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2022-08-22
    • 1970-01-01
    • 2019-05-28
    • 2017-11-30
    相关资源
    最近更新 更多