当前位置:   article > 正文

使用selenium,但chrome无法启动,需要安装浏览器对应版本(最新)的chromedriver_selenium-chrome

selenium-chrome

使用selenium,但chrome无法启动,需要安装浏览器对应版本(最新)的chromedriver


一、问题描述

  • 使用selenium无法启动chrome,代码
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
driver.close()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 报错如下:
D:\python\python.exe D:\pycode\mypycode\case\test06_login.py 
Traceback (most recent call last):
  File "D:\python\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    creationflags=self.creationflags)
  File "D:\python\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "D:\python\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\pycode\mypycode\case\test06_login.py", line 9, in <module>
    driver = webdriver.Chrome()
  File "D:\python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    service_log_path, service, keep_alive)
  File "D:\python\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
    self.service.start()
  File "D:\python\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

二、安装最新版本

  • 安装地址

    • 查询了浏览器版本:117.0.5927在这里插入图片描述

    • 但是国内的镜像网找不到,只更新到114版本

    • 需要安装驱动,点击了最下面的网址https://chromedriver.chromium.org/home

    • 如图为有效信息在这里插入图片描述 - 点击跳转:https://googlechromelabs.github.io/chrome-for-testing(点击这里直接找到114以后的版本)在这里插入图片描述

    • 找到对应版本,点击下载即可
      在这里插入图片描述

    • 解压到python.exe目录下

在这里插入图片描述

  • 复制chromedriver.exe到chrome的安装目录下
    在这里插入图片描述

  • 配置环境变量

在这里插入图片描述

三.测试成功

  • 跑一下
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
sleep(3)
driver.close()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 成功在这里插入图片描述
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/82184
推荐阅读
相关标签
  

闽ICP备14008679号