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。(感觉没什么用)

  • 相关阅读:
    程序员式的幽默(灌水)
    你应该知道的
    WPF控件应用[0]
    WPF控件应用[2]
    C#调用Win32 的API函数User32.dll
    C#获取当前行号
    C#导入excel重写
    [转]wpf相关好资源
    使用C#和Excel进行报表开发-生成统计图Chart
    [转]用 delphi 创建一个服务程序
  • 原文地址:https://www.cnblogs.com/ybbybb/p/14264755.html
Copyright © 2011-2022 走看看