• selenium 执行driver = webdriver.Firefox()时报错解决方案


    执行driver = webdriver.Firefox()时报错如下:

    Traceback (most recent call last):
    File "D:/Python27/baidu.py", line 2, in <module>
    driver = webdriver.Firefox()
    File "D:Python27libsite-packagesseleniumwebdriverfirefoxwebdriver.py", line 164, in __init__
    self.service.start()
    File "D:Python27libsite-packagesseleniumwebdrivercommonservice.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
    WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

    解决 方法:

    步骤1:找到D:Python27Libsite-packagesseleniumwebdriverfirefox下的webdriver.py打开并编辑

    步骤2:确认webdriver.py文件下__init__函数存在executable_path="geckodriver",这说明路径是存在的,但是没起作用。

    步骤3:

    第一步下载geckodriver.exe:下载地址:https://github.com/mozilla/geckodriver/releases请根据系统版本选择下载;(如Windows 64位系统)

    如果网址无法访问:

    百度云盘:https://pan.baidu.com/s/1o7Nj2tW

    分享码:mdv5

    第二步根据自身系统下载解压后将getckodriver.exe复制到浏览器安装目录,如:C:Program Files (x86)Mozilla Firefox,然后目录路径添加到环境变量path下;再把geckodriver.exe复制到python安装目录,如:C:Users15057AppDataLocalProgramsPythonPython36

     打开脚本,重新运行,该问题解决。

    安装三大浏览器驱动driver

         1.chromedriver 下载地址:https://code.google.com/p/chromedriver/downloads/list

         2.Firefox的驱动geckodriver 下载地址:https://github.com/mozilla/geckodriver/releases/

         3.IE的驱动IEdriver 下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

    注意:下载解压后,将chromedriver.exe , geckodriver.exe , Iedriver.exe发到Python的安装目录,例如 D:python 。 然后再将Python的安装目录添加到系统环境变量的Path下面。

  • 相关阅读:
    SpringBoot 项目瘦身
    对比两个文本的异同
    Spring 事务不起作用的场景
    Controller 层数据校验实现思路
    Notify 类的实现思路
    backup: 使用 vim 时一定会用到的设置 --for-myself
    exercise: 反射获取指定的属性值 --CSharp
    exercise: 序列化和反序列化Xml --CSharp
    前缀
    华罗庚的数学思想
  • 原文地址:https://www.cnblogs.com/bzdmz/p/10320514.html
Copyright © 2020-2023  润新知