如何正确设置 selenium 中的 firefox 配置文件?

How to setup firefox profile in selenium correctly?

我在 python 中有以下用于 selenium 的代码来使用我的 firefox 配置文件,目的是避免我每次都登录到我经常访问的页面,但 Selenium 仍然没有 [=15] =] 或 'history' 我正在登录这些页面并保持登录状态。

请问有什么问题吗?

def create_selenium_FF():
    options = Options()
    profile = webdriver.FirefoxProfile('/Users/Victor 1/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
    driver = webdriver.Firefox(profile)
    driver = webdriver.Firefox()
    return driver

通常这样就可以了

from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile

profile = FirefoxProfile("C:\Path\to\profile")
driver = webdriver.Firefox(profile)

As some of the options, such as firefox_profile and options.profile are mutually exclusive, precedence is given from how specific the setting is. capabilities is the least specific keyword argument, followed by options, followed by firefox_binary and firefox_profile.

In practice this means that if firefox_profile and options.profile are both set, the selected profile instance will always come from the most specific variable. In this case that would be firefox_profile. This will result in options.profile to be ignored because it is considered a less specific setting than the top-level firefox_profile keyword argument. Similarily, if you had specified a capabilities[“moz:firefoxOptions”][“profile”] Base64 string, this would rank below options.profile.

看不到你的完整代码,但看起来你在上面有答案

在这里阅读所有内容:- https://selenium-python.readthedocs.io/api.html?highlight=profile#module-selenium.webdriver.firefox.webdriver