当前位置: 首页 > 知识库问答 >
问题:

Selenium和Geckodriver的路径问题

燕玉堂
2023-03-14
#! python3
from selenium import webdriver
browser = webdriver.Firefox()

并得到以下错误消息:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Alex/Anaconda/Templates/selenium_firefox.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1029777f0>>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 163, in __del__
    self.stop()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
[Finished in 0.501s]

我找到了一个似乎可以解决我的问题的答案:使用Python-GeckoDriver可执行文件的Selenium需要在PATH中

但我不太明白如何操作计算机中的路径或如何以计算机工作的方式组织我的文件。

共有1个答案

闻人宝
2023-03-14

我也犯了同样的错误,下面是步骤:

麦克:

>

  • 从以下链接下载geckodriver for MacOS:

    echo $PATH
    

    通常路径是/usr/local/bin。

    将geckodriver从下载文件夹复制到步骤2中获得的路径。使用以下命令:

    cp downloads /usr/local/bin 
    

    注意:有时在执行第3步时,您可能会得到一个权限拒绝错误,要解决此错误,您应该在命令前面使用sudo,如下所示:

    sudo cp downloads /usr/local/bin
    

  •  类似资料:
    • 我已经尝试了其他帖子中找到的解决方案,但没有任何成功。 谢谢。

    • 我非常熟悉在selenium中使用chromedriver,我现在尝试使用geckdriver,但由于某些原因,我不断收到错误信息,geckodriver可执行文件需要在PATH中 我使用Python遵循了Selenium中的步骤-Geckodriver可执行文件需要在PATH中 > 我在环境变量中的path中添加了gecko驱动程序 我将firefox更新为最新版本 我用了二进制方法 把壁虎司机

    • 我已经写了一个基本的脚本,试图打开一个网站与硒(webdriver)。 当我启动上面的脚本时,Firefox浏览器弹出,但它仍然是空白的,它不导航到提到的网站(在本例中是Google)?我确实在终端屏幕上得到一个错误: 跟踪(最近的调用是最后一次):文件“test.py”,第10行,在driver=webdriver.firefox()文件“/usr/local/lib/python3.6/dis

    • 我在OS Sierra上运行Python3.5.2。我已经安装了selenium,我正在阅读一本名为“用Python自动化无聊的任务”的书。 我的密码是 我一直收到错误 我已经广泛地寻找解决我的问题的方法。很多人都有同样的问题。但没有一个解决方案奏效。我已经在我的Python文件夹中到处复制了geckodriver。我试过使用terminal,也试过在代码中指定路径,但它仍然给我错误。我希望有人能

    • 目前我正在使用 硒-3.3.0 火狐-52.2.0 壁虎驱动器-13

    • 问题内容: 我将Maven约定用于源路径(src / main src / test),并且我的sql脚本位于src / main / resources / scripts中。 我想用H2内存运行我的应用程序,我想使用jdbc url初始化我的数据库: 我的问题是,这个相对路径(src / main / …)不起作用,并且如果init = runscript命令什么都没有针对,则H2不会崩溃。