【问题标题】:Selenium Chromedriver executable needs to be in path ( IT IS) [duplicate]Selenium Chromedriver 可执行文件需要在路径中(它是)[重复]
【发布时间】:2020-03-08 22:54:36
【问题描述】:

安装了 Selenium 并构建了最新的稳定 Chromedriver。

按照建议我把它放到环境变量路径中:

我的代码如下所示:

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")

prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)

driver = webdriver.Chrome('./driver/chromedriver', options=options)

timeout = 3

我得到的错误是:

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

我什至在命令行中尝试了以下操作:

chromedriver --whitelisted-ips=""

谁能帮我解决这个问题。

整个输出错误是这样的:

FileNotFoundError Traceback(最近一次调用最后一次) ~\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py in start(self) 75 标准错误=self.log_file, ---> 76 标准输入=管道) 77 除了 TypeError:

~\Anaconda3\lib\subprocess.py in init(self、args、bufsize、executable、stdin、stdout、stderr、preexec_fn、close_fds、shell、cwd、env、universal_newlines、startupinfo、 creationflags、restore_signals、start_new_session、pass_fds、编码、错误、文本) 第774章 --> 775 恢复信号,开始新会话) 776 除了:

~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, used_restore_signals ,未使用的_start_new_session) 第1177章 -> 1178 启动信息) 第1179章:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
<ipython-input-9-3b7827e2d128> in <module>
      2 from selenium import webdriver
      3 
----> 4 driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
      5 driver.get('http://www.google.com/');
      6 time.sleep(5) # Let the user actually see something!

~\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     71             service_args=service_args,
     72             log_path=service_log_path)
---> 73         self.service.start()
     74 
     75         try:

~\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

【问题讨论】:

  • 只需将 chromedriver 放入 c:\windows - 将垃圾添加到您的路径是没有意义的。
  • 我希望这是个玩笑。将垃圾添加到 Windows 目录比将垃圾添加到路径要糟糕得多。 (在调用脚本之前,可以选择在本地更改 PATH。)

标签: python selenium web-scraping selenium-chromedriver


【解决方案1】:

路径条目必须是C:\Users\skpok\Downloads\chromedriver_win32 而不是C:\Users\skpok\Downloads\chromedriver_win32\chromedriver.exe

PATH 环境变量列出了要在其中搜索程序的文件夹。它没有列出程序本身。

(根据您当前的配置,文件的完整路径必须是 C:\Users\skpok\Downloads\chromedriver_win32\chromedriver.exe\chromedriver.exe 才能找到。)


另外,您似乎实际上是在 指定 chrome 驱动程序路径:

driver = webdriver.Chrome('./driver/chromedriver', options=options)

./driver/chromedriver 的路径与您之前显示的路径冲突...尝试删除此参数,以便它实际上PATH 中查找,或者在此处指定正确的文件路径! p>

【讨论】:

  • 我尝试了这两个建议,但没有任何改变 :( 我哪里出错了,或者我怎么能找到错误?
  • 如果您最近才添加此条目,请注销并重新打开或重新启动计算机。
  • 也试过了..只是不想工作:(
  • 我现在注意到另一个问题,我更新了我的答案。您实际上是在指定文件路径:./driver/chromedriver!
  • 很好,不幸的是它仍然不起作用。这太令人沮丧了:(
猜你喜欢
  • 2017-03-26
  • 1970-01-01
  • 2018-12-14
  • 2021-08-19
  • 1970-01-01
  • 2015-07-03
相关资源
最近更新 更多