【问题标题】:How do I open Firefox and set a new profile as default? (selenium and Python) [duplicate]如何打开 Firefox 并将新配置文件设置为默认配置? (硒和Python)[重复]
【发布时间】:2020-03-15 14:30:12
【问题描述】:

好吧,所以我浪费了一整天的自我研究并失败了。所以帮忙? 我创建了一个配置文件,我要做的就是在该配置文件下打开 Firefox,并将其设置为默认值。

这里是代码

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

ff_options = Options()
#profile
binary = FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
profile = webdriver.FirefoxProfile('C:\\Users\\bravoj\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\7k4o5psw.CCC Deafualt')
ff_driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path='C:\\Users\\bravoj\Downloads\\geckodriver.exe')
#fire fox driver

ff_driver.get('about:profiles')

【问题讨论】:

  • 您能说说您使用的是哪个版本的 Firefox 浏览器和 webdriver 驱动程序吗?
  • @KiranAntony 它的 70.0.1

标签: python selenium selenium-firefoxdriver firefox-profile


【解决方案1】:

Selenium 确实使用了配置文件的副本,尽管这应该不会导致任何问题。我认为您的问题更多地与会话 cookie 与持久性 cookie 有关。

support.mozilla.org 上有一个列表,表明您的个人资料中实际存储了哪些信息。请注意,cookie 就是其中之一,但是 session-cookie 不存储在 cookies.sqlite 中,这就是 Selenium 无法重建会话的原因,因为它没有出现在配置文件中。

但是,许多网站在其登录页面上提供了记住我或保持登录选项,如果使用该选项,将存储一个持久性 cookie,通过该 cookie 可以恢复会话。我使用以下脚本通过 gmail 进行了测试,

from selenium import webdriver
url = "https://mail.google.com"
fp = webdriver.FirefoxProfile('/Users/<username>/Library/Application Support/Firefox/Profiles/71v1uczn.default')
driver = webdriver.Firefox(fp)
driver.get(url)

【讨论】:

  • 我最终复制了您的代码,只将配置文件的目录更改为我的。我得到了我需要壁虎驱动程序的错误,我假设没有它就无法工作?我希望真正打开实际的浏览器而不是测试环境。
  • 在分析中给出“默认”应该打开真正的浏览器
  • 很抱歉,我还是新手,才服用了 5 天。但我能举个例子吗?因为我把配置文件改成默认配置文件还是不行。
  • from selenium import webdriver url = "" fp = webdriver.FirefoxProfile('C:\\Users\\\\AppData\\Local\\Mozilla\\Firefox\ \Profiles\\t18zcb43.default') driver = webdriver.Firefox(fp) driver.get(url)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-22
  • 1970-01-01
  • 2012-01-09
  • 2021-02-01
相关资源
最近更新 更多