【问题标题】:How to load a existing FirefoxProfile through Selenium and Python如何通过 Selenium 和 Python 加载现有的 FirefoxProfile
【发布时间】:2018-12-13 10:47:38
【问题描述】:

第一次在这里发帖,所以我解决了一个我无法解决的问题。检查了 Stackoverflow 和谷歌。 java有一些我无法解码的答案。因此,您可能会提到这是重复的,但到目前为止还没有人回答这样的问题。

任何想法都将不胜感激。

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

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
binary = FirefoxBinary(r'C:\Program Files (x86)\MozillaFirefox\firefox.exe')
profile = FirefoxProfile(r'C:\Users\User\Documents\dxcwavid.Zydrius5')
driver = webdriver.Firefox(firefox_profile = profile, firefox_binary = binary)
driver.get("http://google.com")

geckodriver:0.23.0

蟒蛇:3.7.1

硒:3.141.0

窗口:10 1511

【问题讨论】:

    标签: python selenium firefox selenium-webdriver firefox-profile


    【解决方案1】:

    尝试:

    binary = FirefoxBinary("C:\Program Files (x86)\MozillaFirefox\firefox.exe")
    profile = FirefoxProfile("C:\Users\User\Documents\dxcwavid.Zydrius5")
    driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)
    driver.get("http://google.com")
    

    【讨论】:

    • SyntaxError '(Unicodeescape)' code can't decode bytes in position 2-3: Truncated \UXXXXXXXX escape
    • 尝试遵循本指南:stackoverflow.com/a/52935424/10413416
    • 这就是为什么我把'r'放在字符串之前(r'C:\Program Files (x86)\MozillaFirefox\firefox.exe')。除了代码运行完美之外,这不可能是语法问题,而是我错过了一些东西或者必须在 Geckodrive 的某个地方......
    【解决方案2】:

    要通过 SeleniumPython 加载 现有 Firefox 配置文件,您可以使用以下解决方案:

    【讨论】:

    • @ZydrunasAgniauskas Of-coarse 它对我来说完美无瑕。您能否使用最新的代码试验和错误堆栈跟踪更新问题以进行进一步分析?
    • from selenium import webdriver myprofile = webdriver.FirefoxProfile(r'C:\Users\User\Documents\Profile\dxcwavid.Zydrius5') driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Users\User\Documents\Profile\geckodriver.exe') driver.get('https://www.google.co.in') print("Page Title is : %s" %driver.title) 然后我添加到收藏夹,再次打开,没有任何标记为收藏。无法提供任何错误,因为它不会产生任何错误:) 还有我的 Firefox 版本 64.0(32 位)
    • 据我所知,这甚至不会打扰我的个人资料 :)
    • @ZydrunasAgniauskas 在此答案的第二个参考讨论中浏览链接在 Windows 上创建新的 Firefox 配置文件dxcwavid.Zydrius5 是如何登陆C:\Users\User\Documents\Profile 的?
    猜你喜欢
    • 1970-01-01
    • 2020-11-03
    • 2019-05-26
    • 1970-01-01
    • 2019-03-07
    • 2013-09-02
    • 2022-01-08
    • 2018-01-17
    相关资源
    最近更新 更多