Anaconda环境设置Selenium的浏览器驱动程序

在windows中用anaconda环境开发测试Selenium中报错:

Traceback (most recent call last):
  File "D:\Anaconda3\envs\myenv36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "D:\Anaconda3\envs\myenv36\lib\subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "D:\Anaconda3\envs\myenv36\lib\subprocess.py", line 1017, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/share/python/selenium/test_baidu.py", line 3, in <module>
    driver = webdriver.Chrome()
  File "D:\Anaconda3\envs\myenv36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "D:\Anaconda3\envs\myenv36\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://sites.google.com/a/chromium.org/chromedriver/home

根据错误提示信息,selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
得知,chromedrive的驱动程序不存在,需要将驱动程序下载并添加到环境变量PATH中。

各个浏览器的下载驱动程序地址
GeckoDriver(Firefox):https://github.com/mozilla/geckodriver/releases
ChromeDriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home
IEDriverServer(IE):http://selenium-release.storage.googleapis.com/index.html
OperaDriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases
MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/

由于我本地的python运行环境是Anaconda的虚拟配置环境env环境,所以把下载的驱动chromedrive.exe程序放到D:/Anaconda3/envs/myenv36下, 具体参考你anaconda的安装路径。

posted @   phper-liunian  阅读(1185)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示