You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium启动Firefox报executable_path等弃用警告该如何解决?

问题原因

Selenium 4.0及以上版本不再支持直接向webdriver.Firefox()传入executable_path、firefox_binary参数,二者均已被废弃,需要通过Service对象和Options对象来分别配置驱动路径和浏览器路径。

修复步骤
  • 新增导入Firefox对应的Service类和Options类
  • 用Service类封装geckodriver驱动路径
  • 用Options类封装Firefox浏览器二进制路径(如果是默认安装路径可以省略该配置)
  • 初始化浏览器实例时传入构造好的service和options参数
完整修改后的代码示例
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
# 新增导入Service、Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
from selenium.webdriver.common.keys import Keys
import datetime as dt
import urllib.parse

# 配置geckodriver驱动服务
service = Service(executable_path='C:/Users/jinwoo/geckodriver.exe')
# 配置Firefox浏览器选项
options = Options()
# 替换原来的firefox_binary参数,不需要自定义路径可以删掉下行
options.binary = FirefoxBinary('你的Firefox浏览器实际安装路径')

# 初始化浏览器实例
browser = webdriver.Firefox(service=service, options=options)
额外说明

如果你的Firefox是系统默认路径安装,不需要单独指定浏览器位置,可直接省略Options相关配置,简化写法如下:

service = Service(executable_path='C:/Users/jinwoo/geckodriver.exe')
browser = webdriver.Firefox(service=service)

内容的提问来源于stack exchange,提问作者hey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 09:15:02