zoukankan      html  css  js  c++  java
  • 使用selenium时出现 " FileNotFoundError: [WinError 2] 系统找不到指定的文件。" 的解决办法。

    python代码:

     1 from selenium import webdriver
     2 
     3 
     4 def base_driver():
     5     driver = webdriver.Chrome()
     6     driver.maximize_window()
     7     driver.get("https://www.baidu.com")
     8     return driver
     9 
    10 
    11 if __name__ == '__main__':
    12     base_driver()

    报错信息:

    1 Traceback (most recent call last):
    2   File "E:练习项目代码project--pythondata_systemvenvlibsite-packagesseleniumwebdrivercommonservice.py", line 72, in start
    3     self.process = subprocess.Popen(cmd, env=self.env,
    4   File "D:softwarepythonlibsubprocess.py", line 854, in __init__
    5     self._execute_child(args, executable, preexec_fn, close_fds,
    6   File "D:softwarepythonlibsubprocess.py", line 1307, in _execute_child
    7     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
    8 FileNotFoundError: [WinError 2] 系统找不到指定的文件。

    错误的原因提示系统找不到指定的文件,导致错误的原因,找不到chromedriver

    解决方法:

    1。修改代码,把chromedrive安装路径填入,如下:

    driver = webdriver.Chrome("C:/Program Files/Google/Chrome/Application/chromedriver.exe")

    2。把chromedriver.exe的文件放在python安装路径中,如:D:softwarepythonchromedriver.exe

    3。修改电脑中Python安装目录中的lib下的subprocess.py文件中__init__中的shell=False。(感觉没什么用)

  • 相关阅读:
    linux tar order
    Linux驱动学习步骤(转载)
    汇编指令(转载)
    拓扑排序
    python 三维坐标图
    python 矩阵
    spring 之 IOC 依赖注入详解
    spring 下载
    Struts数据验证
    拦截器配置
  • 原文地址:https://www.cnblogs.com/ybbybb/p/14264755.html
Copyright © 2011-2022 走看看