Selenium 仅以已弃用的方式加载配置文件 (Python)

发布于 2025-01-16 05:21:14 字数 773 浏览 4 评论 0原文

我尝试了推荐的加载配置文件的方法,但它对我不起作用。它只是打开一个空的配置文件。

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options


profile_path = r'E:/Python/seleniumProfile'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
driver.get("https://www.google.com")

即使我输入无效的文件夹作为 profile_path,也不会给出警告或错误消息。

旧方法效果很好,但会给出弃用警告:

fp = webdriver.FirefoxProfile('E:/Python/seleniumProfile')
driver = webdriver.Firefox(fp)
driver.get("https://www.google.com")

DeprecationWarning:firefox_profile 已被弃用,请使用选项对象

我想我可以忍受这些警告,但任何帮助将不胜感激。

I tried the recommended method of loading a profile, but it's not working for me. It simply opens an empty profile.

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options


profile_path = r'E:/Python/seleniumProfile'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
driver.get("https://www.google.com")

No warning or error message is given, even if I type an invalid folder as the profile_path.

Old way works great, but gives the deprecation warning:

fp = webdriver.FirefoxProfile('E:/Python/seleniumProfile')
driver = webdriver.Firefox(fp)
driver.get("https://www.google.com")

DeprecationWarning: firefox_profile has been deprecated, please use an Options object

I guess I can live with the warnings, but any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡寂寞咖啡 2025-01-23 05:21:14

此错误消息...

firefox_profile has been deprecated, please pass in an Options object

...意味着 FirefoxProfile() 的使用已弃用,并且 并使用自定义配置文件,您必须使用选项的实例。此弃用警告与以下变更日志一致:


解决方案

要使用现有的 firefox 配置文件,您可以使用以下解决方案:

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\s8543x41.default-release'
options=Options()
options.set_preference('profile', profile_path)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")

tl; dr

设置自定义配置文件

This error message...

firefox_profile has been deprecated, please pass in an Options object

...implies that usage of FirefoxProfile() have been Deprecated and with and to use a custom profile you have to use an instance of Options . This DeprecationWarning was inline with the following CHANGELOGS:


Solution

To use an existing firefox profile you can use the following solution:

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\s8543x41.default-release'
options=Options()
options.set_preference('profile', profile_path)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")

tl; dr

Setting a custom profile

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文