【问题标题】:How to use Firefox profiles in Selenium Python (windows)如何在 Selenium Python (windows) 中使用 Firefox 配置文件
【发布时间】:2021-09-09 20:14:41
【问题描述】:

我无法在 Selenium Webdriver 上加载我的 Firefox 配置文件。

我已经尝试了几种方法在这里评论 SO,但没有成功。要么我与驱动程序的连接松动,要么配置文件没有加载。

这是我目前所拥有的:

from selenium import webdriver
options = Options()
options.headless = False
fp = webdriver.FirefoxProfile(r'C:\\Users\\xxXX\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\y73h6ogb.default-release')
driver = webdriver.Firefox(fp, options=options, executable_path='geckodriver/geckodriver.exe')

driver.get(URL)

【问题讨论】:

  • 是的,但我无法让它工作。继续获取临时配置文件

标签: python selenium selenium-webdriver


【解决方案1】:

根据documentation,您可以像这样加载配置文件:

from selenium.webdriver import Firefox, FirefoxOptions, FirefoxProfile


options = FirefoxOptions()
options.headless = True

profile = FirefoxProfile("PATH_TO_PROFILE\\1234asdf.some_profile")

driver = Firefox(
    firefox_profile=profile,
    executable_path="PATH_TO_DRIVER\\geckodriver.exe",
    options=options,
)

driver.get("https://python.org")
driver.close()

或者通过将配置文件添加到options

...
options = FirefoxOptions()
options.headless = True
options.profile = FirefoxProfile("PATH_TO_PROFILE\\1234asdf.some_profile")

driver = Firefox(
    executable_path="PATH_TO_DRIVER\\geckodriver.exe",
    options=options,
)
...

【讨论】:

    【解决方案2】:

    通过使用 webdriver for firefox,您将能够做到这一点!

    【讨论】:

      猜你喜欢
      • 2018-02-08
      • 2018-10-23
      • 1970-01-01
      • 2016-09-11
      • 2013-10-16
      • 2018-01-13
      • 2016-03-23
      • 2016-06-25
      • 2021-02-13
      相关资源
      最近更新 更多