繁体   English   中英

使用python-硒包时出错

[英]error while using python- selenium package

我正在尝试使用selenium软件包连接到Web浏览器的基本python脚本。 错误日志如下所示。

Traceback (most recent call last):
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "F:/WinPython/WinPython-64bit-3.5.2.3Qt5/python-3.5.2.amd64/py_codes/python_org_search.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
    self.service.start()
  File "F:\WinPython\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

来自selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. ,很明显,您需要将geckodriver添加到系统路径,更具体地说,应将包含geckodriver.exe的文件夹添加到系统路径。

为此,请以管理员身份运行cmd.exe并运行以下命令:

setx path "%path%;C:\Path\to\geckodriver.exe\;"

C:\\Path\\to\\geckodriver.exe\\替换为包含geckodriver.exe的文件夹的确切路径

编辑:

您可以从此处https://github.com/mozilla/geckodriver/releases下载exe文件,将其解压缩到某个位置,例如C:\\geckodriver 现在,您拥有像C:\\geckodriver\\geckodriver.exe这样的文件,并且需要将C:\\geckodriver添加到系统路径。 并且,在新控制台中运行脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM