【问题标题】:Selenium chromedriver not working on mac? [duplicate]Selenium chromedriver 无法在 Mac 上运行? [复制]
【发布时间】:2020-05-09 21:03:47
【问题描述】:

这几天我一直在尝试学习 Selenium 的基础知识,但我一直遇到同样的障碍。

错误:

消息:“chromedriver”可执行文件需要在 PATH 中。请看https://sites.google.com/a/chromium.org/chromedriver/home

尽管 chromedriver 和我的 python 代码在同一个文件夹中,但仍然出现。有没有什么办法解决这一问题?我正在运行的代码在这里:

    import time
    from selenium import webdriver

    driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
    driver.get('http://www.google.com/');

【问题讨论】:

  • “尽管 chromedriver 和我的 python 代码在同一个文件夹中,但仍然出现。” - 这不是错误消息告诉你的。

标签: python selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

您可以将executable_path 添加到您的webdriver.Chrome() 声明中,并提供chromedriver.exe 所在位置的完整路径:

driver = webdriver.Chrome(executable_path="/usr/path/to/chromedriver.exe")

executable_path 中的字符串需要替换为系统中指向 chromedriver 可执行文件的绝对路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-07
    • 2017-04-24
    • 2017-01-24
    • 1970-01-01
    • 2019-11-08
    • 2020-11-27
    • 2014-03-23
    相关资源
    最近更新 更多