已安装 chrome 驱动程序并将其添加到路径中,但错误显示 Chromedriver 需要在路径中

Installed chrome driver and added it to path yet error shows Chromedriver needs to be in path

提问人:Dave123gt 提问时间:5/29/2020 更新时间:9/6/2021 访问量:546

问:

嘿,伙计们,所以我试图制作一个需要 chromedriver 和 我下载了 chrome webdriver 并使用命令行导入了 selenium。我在 path 中添加了 webdriver 并指定了位置,但 weeoes 显示无法找到该文件并且 chromedriver 需要在路径中

如果有人需要更多信息,我很乐意提供,我将不胜感激有人试图为我测试代码,请告诉我,以便我可以在 github 上分享它

subprocess.py

self._execute_child(args, executable, preexec_fn, close_fds,
                                pass_fds, cwd, env,
                                startupinfo, creationflags, shell,
                                p2cread, p2cwrite,
                                c2pread, c2pwrite,
                                errread, errwrite,
                                restore_signals, start_new_session)

 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                                         # no special security
                                         None, None,
                                         int(not close_fds),
                                         creationflags,
                                         env,
                                         cwd,
                                         startupinfo)

service.py

self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file,
                                            stderr=self.log_file,
                                            stdin=PIPE) 


raise WebDriverException(
                    "'%s' executable needs to be in PATH. %s" % (
                        os.path.basename(self.path), self.start_error_message

Webdriver.py

  self.service = Service(
            executable_path,
            port=port,
            service_args=service_args,
            log_path=service_log_path)
        self.service.start()

Davids_Chegg.py

chrome_driver = r'C:\Webdrivers\chromedriver.exe\'

if __name__ == '__main__':
    browser = webdriver.Chrome("C:\Webdrivers\chromedriver.exe")
    signin()
    client.run(bot_token)
    # test comment
ERRORS:

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\david\Desktop\Python\chegg_bot\David_s Chegg.py", line 282, in <module>
    browser = webdriver.Chrome(executable_path="chromedriver", options=opts)
  File "C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
python selenium chrome-web-driver

评论


答:

0赞 Sonal Savaliya 5/29/2020 #1

您可以尝试下面的代码,您无需担心根据 Web 浏览器版本设置或 Web 驱动程序安装。

只需使用命令安装webdriver_manager即可使用此代码:pip install webdriver_manager

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

我正在将其用于网络抓取,并且效果很好。

0赞 Birappa Goudanavar 9/6/2021 #2

要遵循的步骤

  1. 转到本地 c 并找到 Python 文件目录

  2. 并将 Drive 可执行文件粘贴到 Python 文件夹中

  3. 再次运行脚本

它将 100% 工作