解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu

运行爬虫代码出现上面的bug

bug详细信息如下

D:\Anaconda3\file\envs\item\python.exe D:/pycharm/code/BadmintonCrawler.py
D:\pycharm\code\BadmintonCrawler.py:22: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(executable_path=r"1D:\Anaconda3\file\envs\item\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe", options=options)
Traceback (most recent call last):
  File "D:\Anaconda3\file\envs\item\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "D:\Anaconda3\file\envs\item\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "D:\Anaconda3\file\envs\item\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\pycharm\code\BadmintonCrawler.py", line 102, in 
    bc = BadmintonCrawler()
  File "D:\pycharm\code\BadmintonCrawler.py", line 17, in __init__
    self.__login()
  File "D:\pycharm\code\BadmintonCrawler.py", line 22, in __login
    driver = webdriver.Chrome(executable_path=r"1D:\Anaconda3\file\envs\item\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe", options=options)
  File "D:\Anaconda3\file\envs\item\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "D:\Anaconda3\file\envs\item\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
    self.service.start()
  File "D:\Anaconda3\file\envs\item\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

 解决方法

如下

1.先打开chrome 输入 “chrome://version/”来查看chrome版本 如图我的是96

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第1张图片

 

2.然后访问此网站  http://chromedriver.storage.googleapis.com/index.html   然后选择合适版本的driver 

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第2张图片

 我这边是windows版本的系统所以下载  win32版本的压缩包

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第3张图片

 解压后里面是个这个东西

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第4张图片

3.  把解压后的   chromedriver.exe  文件放入  python  所在的环境中

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第5张图片

4.  之后再把代码中的路径 修改成上面文件放入的路径 

driver = webdriver.Chrome(executable_path=r"D:\Anaconda3\file\envs\item\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe", options=options)

 然后运行就可以了

解决:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ execu_第6张图片

 之前的bug就解决了,上面的这个是另外的其他的bug

你可能感兴趣的:(爬虫,python,windows,chrome,selenium)