更新时间:2022-02-19 22:41:38
解决方案:
from selenium import webdriver
fp = webdriver.FirefoxProfile('/home/gabriel/.mozilla/firefox/whatever.selenium')
driver = webdriver.Firefox(fp)
我一直努力直到找到此问题,该问题现已解决,但由于有帮助,它显示了一些命令.
I struggled until I found this issue which is now solved but was helpful because it shows some commands.
第一个版本,无法正常工作,因为之后无法连接硒:
first version, not working because I could not connect with selenium afterward:
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
options = Options()
options.add_argument("-profile")
options.add_argument("/home/gabriel/.mozilla/firefox/whatever.selenium")
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
driver = webdriver.Firefox(capabilities=firefox_capabilities, firefox_options=options)
我确信这会加载配置文件"whatever.selenium",因为如果我转到about:profiles,我会读到:
I am sure that this loads the profile "whatever.selenium" because if I go to about:profiles I can read:
配置文件:硒 这是正在使用的配置文件,无法删除.
Profile: selenium This is the profile in use and it cannot be deleted.
即使"whatever.selenium"不是系统上的默认配置文件.
Even though "whatever.selenium" is not the default profile on my system.
备注:硒(或geckodriver?)至少覆盖了一个配置文件参数:首选项>隐私和安全性>阻止弹出窗口"始终重置为关闭状态.因此,使用about:profiles可以断言您正在运行的配置文件.
注释:
firefox_capabilities
.firefox_capabilities
might not be needed in above code.