如何在Python中使用Selenium创建一个新的(持久的)Firefox配置文件? [英] How to create a new (persistent) Firefox profile with Selenium in Python?

查看:176
本文介绍了如何在Python中使用Selenium创建一个新的(持久的)Firefox配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Trynig用Selenium添加一个新的,持久的Firefox配置文件。 AFAIK,当执行 FirefoxProfile()时,使用临时文件生成一个新的配置文件。理想情况下,即使在创建者关闭之后,此配置文件也应该能够保留在后续进程中。

问题


  1. 创建一个新的Firefox Python代码中的配置文件。这应该返回一个FirefoxProfile对象,可用于Selenium使用的Firefox webdriver。

  2. 创建的配置文件在进程结束后应该保持不变 - 即它应该是一个完整的配置文件,临时配置文件。

一些指针


  1. profiles.ini 文件似乎很重要。我已经阅读了一些使用Java类 ProfilesIni 的代码来修改配置文件信息。如果这个类可用于Python代码,那么它应该可以处理大部分的代码。

  2. 如果唯一的方法是手动修改 profiles.ini 文件,这是可以接受的。然而,一个更好,更标准化的解决方案(使用库或Selenium代码的方案)是最好的选择。

  3. 非常多!

    解决方案

    如果这可以帮助任何人,那么需要做的是:

      firefox [.exe] -CreateProfile< profile_name> 

    括号中的 .exe 提供它在Windows下运行。



    是的,这并不使用Python中的Selenium库,但它提供了所需的结果。 b

    Trynig to add a new, persistent, Firefox profile with Selenium. AFAIK, when executing FirefoxProfile(), a new profile is generated using a temporary file. Ideally, this profile should be able to remain available to subsequent processes - even after the creator is closed.

    Problem:

    1. Create a new Firefox profile from within Python code. This should return a FirefoxProfile object that is usable with the Firefox webdriver Selenium uses.
    2. The profile created should persist after the process ends - i.e. it should be a full-fledged profile, not just a temporary profile.

    Some pointers:

    1. The profiles.ini file seems to be key. I have read some code that uses the Java class ProfilesIni to modify profile information. If this class is available for Python code, it should probably take care of most of this.

    2. If the only way to do this is to manually modify the profiles.ini file, that's acceptable. A better, more standardized solution (one that uses a library or Selenium code) would be preferable, however.

    Thanks very much!

    解决方案

    If this helps anyone, what needs to be done is run:

    firefox[.exe] -CreateProfile <profile_name>
    

    The .exe in brackets is intended to provide for it being run under Windows.

    Yes, this does not use the Selenium library in Python, but it does provide the desired result.

    这篇关于如何在Python中使用Selenium创建一个新的(持久的)Firefox配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆