当前基于python3.9,selenium4.1.0验证
在py代码执行后提示executable_path弃用警告,内容如下:
1 2 |
D:\PycharmProjects\pythonProject\main.py:2: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Firefox(executable_path ="D:\geckodriver\geckodriver") |
原代码内容:
1 2 3 |
from selenium import webdriver driver = webdriver.Firefox(executable_path ="D:\geckodriver\geckodriver") driver.get("https://www.whsir.com/") |
优化后的写法:
1 2 3 4 5 |
from selenium import webdriver from selenium.webdriver.firefox.service import Service driver_service = Service(executable_path="D:\geckodriver\geckodriver") driver = webdriver.Firefox(service=driver_service) driver.get('https://www.whsir.com/') |
修改后完美执行,警告消失
原文链接:DeprecationWarning: executable_path警告弃用,转载请注明来源!