【问题标题】:I am trying to use selenium in pycharm to open firefox. I Have no idea what the problem is我正在尝试在 pycharm 中使用 selenium 来打开 Firefox。我不知道问题是什么
【发布时间】:2020-07-29 05:39:41
【问题描述】:

我正在尝试在 pycharm 中使用 selenium 打开 Firefox。我不知道问题是什么。

-我已经在正确的 PATH 中安装了 geckodriver。 (/usr/local/bin) - 我正在使用 pop_os 20.04 LTS

当我跑步时

from selenium import webdriver

driver = webdriver.Chrome(r'/usr/local/bin')

*Traceback (most recent call last):
  File "/home/elliot/PycharmProjects/IG/venv/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)

  File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)

  File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin': '/usr/local/bin'
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elliot/PycharmProjects/IG/igbot.py", line 3, in <module>
    driver = webdriver.Chrome(r'/usr/local/bin')

  File "/home/elliot/PycharmProjects/IG/venv/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()

  File "/home/elliot/PycharmProjects/IG/venv/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'bin' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1*

【问题讨论】:

    标签: python pycharm geckodriver


    【解决方案1】:

    GeckoDriver 用于控制 Firefox,您正在尝试使用 Chrome

    driver = webdriver.Chrome(...
    #                  ^^^^^^ ???
    

    要么使用 ChromeDriver,要么切换到 Firefox。

    r'/usr/local/bin' 传递给Chrome 构造函数没有意义,假设GeckoDriver 或ChromeDriver 可以在PATH 中找到,则可以省略它。

    有一个不错的库可以自动执行繁琐的驱动程序管理任务,请参阅webdriver-manager

    尝试阅读selenium-python docs 的“安装”和“入门”章节。

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 2022-11-28
      • 2021-11-01
      • 2020-11-25
      • 2023-04-02
      • 2011-02-27
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      相关资源
      最近更新 更多