如何在python中保存Firefox webdriver会话

如何在python中保存Firefox webdriver会话,python,selenium,webdriver,Python,Selenium,Webdriver,为了保存chromedriver会话,我使用了以下代码片段: from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('user-data-dir= path to where to save session') driver = webdriver.Chrome(executable_path='p

为了保存chromedriver会话,我使用了以下代码片段:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Chrome(executable_path='path to chromedriver.exe', chrome_options=options)
我试着用Firefox做同样的事情,但似乎不起作用:

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

options = Options()
options.add_argument('user-data-dir= path to where to save session')
driver = webdriver.Firefox(executable_path='path to geckodriver.exe', firefox_options=options)

这是正确的方法还是我错过了什么?

下面是创建新配置文件并使用现有配置文件启动firefox的手动过程:

  • 要创建新的配置文件,请执行以下命令:
    firefox.exe-CreateProfile-JoelUser

  • 要在另一个目录中创建新的配置文件,请执行以下命令:
    firefox.exe-CreateProfile“JoelUser c:\internet\joelusers moz profile”

  • 要使用新配置文件启动firefox,请执行以下命令:
    firefox.exe-p“Joel User”

  • 现在,为了以编程方式实现同样的目标,我发现步骤1或2可以使用子流程执行,步骤3可以通过以下
    https://stackoverflow.com/a/54065166/6278432

    参考资料:

  • firefox错误-无法使用自定义配置文件创建新会话:

  • Firefox命令行参数-

  • 子流程api文档-


  • 你找到解决办法了吗?我也有同样的问题,搜索了很多,但没有找到答案,如果你分享一个解决方案,这将是一个很大的帮助