我花了大约2个小时(是的,我太慢了)猜测为什么不起作用。我发现了为什么个人资料不保存回去。
当然,传递给
FirefoxProfile("myprofile/full/path")它的配置文件是在运行时使用的,但是它并没有保存回去,因为(也许不是很明显)硒用于测试,并且测试应该在没有缓存,没有任何配置文件,尽可能干净的情况下运行。配置文件功能(可能)是为了允许在运行测试之前安装某些扩展名和设置而创建的,而不是为了保存它们。
诀窍是打印出来
print driver.firefox_profile.path。它与通常的确有所不同,其名称为 tmp / tmpOEs2RR /
webdriver-py-profilecopy,而 不仅仅是 tmp / tmpOEs2RR / ,因此请阅读您应该猜测的配置文件。
现在,剩下的唯一事情就是找回它:)
运行此脚本,安装内容,编辑内容,然后再次运行;):
#!/usr/bin/env python#! -*- coding: utf-8 -*-import seleniumfrom selenium import webdriverimport os, sys, time# 1- set profileprofile = os.path.dirname(sys.argv[0]) + "/selenita"fp = webdriver.FirefoxProfile(profile)driver = webdriver.Firefox(firefox_profile=fp)# 2- get tmp file locationprofiletmp = driver.firefox_profile.path# but... the current profile is a copy of the original profile :/print "running profile " + profiletmpdriver.get("http://httpbin.org")time.sleep(2)raw_input("Press a key when finish doing things") # I've installed an extension# 3- then save backprint "saving profile " + profiletmp + " to " + profileif os.system("cp -R " + profiletmp + "/* " + profile ): print "files should be copied :/"driver.quit()sys.exit(0)您可以遵循该架构,也可以根据需要简单地编辑FirefoxProfilea。



