Selenium Chromedriver可执行文件必须位于路径中(IT IS)

时间:2020-03-08 22:54:36

标签: python selenium web-scraping selenium-chromedriver

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

按照建议,我将其放入环境变量路径:

enter image description here

我的代码如下:

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在开始(自己) 75 stderr = self.log_file, ---> 76 stdin = PIPE) 77,除了TypeError:

init 中的

〜\ Anaconda3 \ lib \ subprocess.py(自身,args,bufsize,可执行文件,stdin,stdout,stderr,preexec_fn,close_fds,shell,cwd,env,universal_newlines,startupinfo, creationflags,restore_signals,start_new_session,pass_fds,编码,错误,文本) 774 errread,errwrite, -> 775 restore_signals,start_new_session) 776除:

_execute_child中的

〜\ Anaconda3 \ lib \ subprocess.py(self,args,可执行文件,preexec_fn,close_fds,pass_fds,cwd,env,startupinfo,creationflags,shell,p2cread,p2cwrite,c2pread,c2pwrite,errreadals,errwrite,未使用,未使用的_start_new_session) 1177 os.fspath(cwd)如果cwd不是None其他None, -> 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:

1 个答案:

答案 0 :(得分:0)

路径条目必须为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中显示,或指定正确的文件路径在这里!